Solved

Set Computer Location & Printer Location with Comment via BAT script (or VBS)

Posted on 2008-10-23
6
546 Views
Last Modified: 2008-10-26
How do I via a BAT script or VBS do the following for both windows XP and 2000?

- Set Computer Description to 'BuildingX, RoomX"
- Set Printer Location (Local Only.. ie LPT, or USB) to be 'Building_X'
- Set Printer Comment "Room X"

Also bonus points for:

- Set C: "HDD name" to be same as 'PC Name'
0
Comment
Question by:EuroITSales
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:gratex_ssd
ID: 22790187
try to find atomic solutions at tehcnet script center

like this for "computer location"
http://www.microsoft.com/technet/scriptcenter/scripts/default.mspx?mfr=true

0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 22790431
Paste the script below into a text file with a .vbs extension.  Customize the values of the strComputerDesc, strPrinterLocation, and strPrinterComment variables as desired.  Running the script will set the specified values.

The computer description may require a reboot to take effect.


Const HKEY_LOCAL_MACHINE = &H80000002
 

strComputer = "."

strComputerDesc = "BuildingX, RoomX"

strPrinterLocation = "Building_X"

strPrinterComment = "Room X"
 

On Error Resume Next
 

Set objRegistry = GetObject _

    ("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
 

strKeyPath = "System\CurrentControlSet\Services\lanmanserver\parameters"

strValueName = "srvcomment"
 

objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strComputerDesc
 
 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set colInstalledPrinters = objWMIService.ExecQuery("SELECT * FROM Win32_Printer")
 

For Each objPrinter in colInstalledPrinters

    If Left(objPrinter.Portname, 3) = "LPT" Or Left(objPrinter.Portname, 3) = "USB" Then

        objPrinter.Location = strPrinterLocation

        objPrinter.Comment = strPrinterComment

        objPrinter.Put_

    End If

Next
 

Set objShell = CreateObject("WScript.Shell")

Set WSHShell = CreateObject("Shell.Application")

strComputerName = objShell.ExpandEnvironmentStrings("%computername%")

WSHShell.NameSpace("C:").Self.Name = strComputerName

Open in new window

0
 

Author Comment

by:EuroITSales
ID: 22790692
Wow, your brilliant!!

Although the System Properties > Computer Description didn't set?

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 38

Expert Comment

by:Shift-3
ID: 22790733
Did you reboot?
0
 

Author Comment

by:EuroITSales
ID: 22790820
Yes, although I'm trying this on Vista (at home!) .. all settings updated apart from Computer Description ... maybe it's 2000/XP only!
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 22792136
I don't know where that setting is stashed in Vista.  Try manually changing the description to something distinctive and then searching for it in Regedit.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now