?
Solved

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

Posted on 2008-10-23
6
Medium Priority
?
565 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

762 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