Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check OS version for script compatability

Status
Not open for further replies.

fr8o

Technical User
Jun 13, 2007
6
US
Here is what I have, it works great if you remove the attempt to setup the if statement, but as windows 2000 and xp SP1 do not have powercfg I have to find a way to limit which version of windows this runs on. I am still in a position of no formal training in vb so I am just hacking this out from trial and error at this point.

Set oShell = CreateObject("Wscript.Shell")
Set version = oShell.Run "ver"

If( UCase( Trim( version ) ) = UCase( Trim( "Microsoft WIndows XP [Versopm 5.1.2600]" ) ) )

Then
oShell.Run "powercfg.exe -change ""Home/Office Desk"" -monitor-timeout-ac 15", 0, True
oShell.Run "powercfg.exe -change ""Home/Office Desk"" -disk-timeout-ac 25", 0, True
oShell.Run "powercfg.exe -change ""Home/Office Desk"" -standby-timeout-ac 0", 0, True
oShell.Run "powercfg.exe -change ""Home/Office Desk"" -hibernate-timeout-ac 0", 0, True
oShell.Run "powercfg.exe -hibernate off", 0, True
oShell.Run "powercfg.exe -setactive ""Home/Office Desk""", 0, True
End If
 
Wouldn't you know right after I posted I found a snippet of code that did the trick, ideas on anything to make this smoother though would be nice:

Set oShell = CreateObject("Wscript.Shell")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
OS = LEFT(objOperatingSystem.Version,3)
next

If( UCase( Trim( OS ) ) = UCase( Trim( 5.1 ) ) ) Then
oShell.Run "powercfg.exe -change ""Home/Office Desk"" -monitor-timeout-ac 15", 0, True
oShell.Run "powercfg.exe -change ""Home/Office Desk"" -disk-timeout-ac 25", 0, True
oShell.Run "powercfg.exe -change ""Home/Office Desk"" -standby-timeout-ac 0", 0, True
oShell.Run "powercfg.exe -change ""Home/Office Desk"" -hibernate-timeout-ac 0", 0, True
oShell.Run "powercfg.exe -hibernate off", 0, True
oShell.Run "powercfg.exe -setactive ""Home/Office Desk""", 0, True
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top