Following is my script my computer startup script in my GP. I'm not very
good in scripting but I managed to put this script together. Two things are
not working right in this script.
Firstly, I want the unistallation process complete before the login prompt
appears but this does not happen. I am using sleep wscript.sleep this is not
ideal and not working well because some machines need longer time and others
need shorter time, depending on the network connection and speed of PCs. In
a thinking in the lines of putting a function where if the uninstall process
begins the login prompt is hidden/disabled or unavailable is until the whole
proccess is completed and rebooted. Please, help me as I need to have this
working by the end of this week.
Secondly, After unistall process completes I want it to reboot the machine
again but this does not happen as well. This probably because not completing
the uninstall process and the using logon interferring but I'm not sure. Is
anything wrong with my RebootPC() function? how can I fix it?
Thank you everyone for your quick help
' ----------------------------------------------------------------
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set WSHShell=WScript.CreateObject("WScript.Shell")
Set fs=CreateObject("Scripting.FileSystemObject")
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\"&_
strComputer & "\root\default:StdRegProv")
rem check if file exist, if it is jump out
If Not fs.fileExists("c:\UninstallOfficepro.log") Then
'WScript.Echo "officepro removed"
'Else
'Set the registry key path And thi
strKeyPath = _
"Software\Microsoft\Windows\CurrentVersion\Uninstall\{90110409-6000-11D3-8CFE-0050048383C9}"
strValueName = "DisplayName"
Return = objReg.GetExpandedStringValue(HKEY_LOCAL_MACHINE,_
strKeyPath,strValueName,strValue)
' If key does exist and display name is Microsoft Office XP
Professional then run uninstall command
If (Return = 0) And (strValue="Microsoft Office XP Professional") And
(Err.Number = 0) Then
rem WScript.Echo "Program is " & strValue & " " & StrKeypath
WshShell.Run _
("%systemroot%\System32\msiexec.exe
/x{90110409-6000-11D3-8CFE-0050048383C9} /passive /qb /l*v
C:\UninstallOfficepro.log")
WScript.Sleep(5000)
'RestartPC()
'WScript.Sleep(5000)
Else
'WScript.Echo _
' "GetExpandedStringValue failed. Error = " & Err.Number
WScript.Quit(0)
End If
End If
WScript.Quit(0)
'
---------------------------------------------------------------------------------
' This function reboots the Pc after uninstalling officepro
Function RestartPC()
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer &
"\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()
Next
End Function