我正在运行以下脚本,卸载sccm 2007客户端,卸载wds,webdav,删除陈旧的注册表项和文件夹,然后在除p驱动器之外的所有驱动器上创建.sms文件,我希望脚本执行操作一个订单,应该从重启后停止的地方选择但是在调用ccmsetup
后我得到了编译错误。我哪里错了?我们可以在执行脚本的过程中调用子程序吗?
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\My Scripts"
strValue = "Componentsuninstallscript"
objRegistry.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValue,strScriptStatus
If IsNull(strScriptStatus) Then
strScriptStatus = "Run"
objRegistry.CreateKey HKEY_CURRENT_USER,strKeyPath`enter code here`
objRegistry.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValue,strScriptStatus
call ccmsetup()
call Wdswebdavuninstall()
strNewKeyPath = "Software\Microsoft\Windows\CurrentVersion\RunOnce"
strNewValue = "Componentsuninstallscript"
Dim WMIServiceObject, ComputerObject
WMIServiceObject = GetObject("Winmgmts:{impersonationLevel=impersonate,(Debug,Shutdown)}")
For Each ComputerObject In WMIServiceObject.InstancesOf("Win32_OperatingSystem")
Rebootserver = ComputerObject.Win32Shutdown(2 + 4, 0)
If Rebootserver <> 0 Then
MsgBox("Sorry, an error has occurred while trying to perform selected operation")
Else
End If
Next
objRegistry.SetStringValue HKEY_CURRENT_USER,strNewKeyPath,strNewValue,strScriptPath
Wscript.Quit
End If
Wscript.Echo "Proceeding to remove folders and registry entries."
On error resume next
Dim Strkeypathm(5)
Dim i
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
strKeyPathm(0) = "SYSTEM\CurrentControlSet\services\WDSMC"
Strkeypathm(1) = "SYSTEM\CurrentControlSet\services\WDSTFTP"
StrKeypathm(2) = "SOFTWARE\Wow6432Node\Microsoft\CCM"
Strkeypathm(3) = "SOFTWARE\Wow6432Node\Microsoft\CCMSetup"
Strkeypathm(4) = "SOFTWARE\Wow6432Node\Microsoft\SMS"
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
For i=0 to 4
DeleteSubkeys HKEY_LOCAL_MACHINE, strKeypathm(i)
Next
Sub DeleteSubkeys(HKEY_LOCAL_MACHINE, strKeyPathm)
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPathm, arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys HKEY_LOCAL_MACHINE, strKeyPathm & "\" & strSubkey
Next
End If
objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strKeyPathm
Call Nosmsondrive()
Call Removalofflders()
objRegistry.DeleteKey HKEY_CURRENT_USER,strKeyPath
Sub ccmsetup()
Set wshshell=wscript.createobject("wscript.shell")
Wscript.echo "Please Wait while SCCM 2007 client is getting uninstalled"
ccmuninstall=wshshell.Run("C:\Windows\CCMSetup\ccmsetup.exe" & " " & "/Uninstall",0,True)
Set objfso=Createobject("scripting.filesystemobject")
Set ccmsetuplog=objfso.opentextfile("C:\Windows\ccmsetup\ccmsetup.log",1)
Do Until ccmsetuplog.AtEndOfStream
strNextLine = ccmsetuplog.ReadLine
If strNextLine="Uninstall succeeded." Then
Wscript.echo "SCCM 2007 client uninstallation is completed"
End If
Loop
ccmsetuplog.Close
End sub
'==========================Uninstall SCCM 2007 Client==========================
'==========================Removal of WDS and WEBDAV===========================
Sub Wdswebdavuninstall()
Set wshshell=wscript.createobject("wscript.shell")
Wscript.echo "Please wait while WEBDAV and WDS are being uninstalled"
Wdsuninst=Wshshell.Run("cmd /c start /w ocsetup Microsoft-Windows-Deployment-Services /Uninstall /quiet /norestart",0,True)
uninstwdv=wshshell.Run("cmd /c start /w dism.exe /online /disable-feature /featurename=IIS-WebDAV /quiet /norestart",0,True)
Wscript.sleep 100000
End Sub
'==========================Removal of WDS and WEBDAV===========================
'==========================Removal of folder Entries===========================
Sub Removalofflders()
Set objfs=Createobject("scripting.filesystemobject")
If objfs.folderexists("P:\Remoteinstall") Then
objfs.Deletefolder "P:\Remoteinstall", True
Else
Wscript.echo "Remoteinsall folder is already deleted"
End If
If objfs.folderexists("P:\SMSPKG") Then
objfs.Deletefolder "P:\SMSPKG", True
Else
Wscript.echo "SMSPKG folder is already deleted"
End If
If objfs.folderexists("P:\SMSPKGP$") Then
objfs.Deletefolder "P:\SMSPKGP$", True
Else
Wscript.echo "SMSPKGP$ folder is already deleted"
End If
If objfs.folderexists("P:\SMSPKGSIG") Then
objfs.Deletefolder "P:\SMSPKGSIG", True
Else
Wscript.echo "SMSPKGSIG folder is already deleted"
End If
If objfs.folderexists("P:\SMSSIG$") Then
objfs.Deletefolder "P:\SMSSIG$", True
Else
Wscript.echo "SMSSIG$ folder is already deleted"
End If
If objfs.folderexists("C:\Windows\Ccmsetup") Then
objfs.Deletefolder "C:\Windows\Ccmsetup", True
Else
Wscript.echo "Ccmsetup folder is already deleted"
End If
If objfs.folderexists("C:\Windows\Syswow64\CCM") Then
objfs.Deletefolder "C:\Windows\Syswow64\CCM", True
Else
Wscript.echo "CCM folder is already deleted"
End If
Wscript.echo "All stale folders and registry entries are removed"
End sub
'==========================Removal of folders entries==========================
'==========================Creation of NO_SMS_ON_DRIVE.SMS=====================
Sub Nosmsondrive()
Set Wmiconnection=Getobject("winmgmts:{impersonationLevel=impersonate}!\\" & "."&"\root\cimv2")
Set Drives=wmiconnection.execquery("Select * from win32_Logicaldisk where drivetype='3'")
For each Drive in Drives
If Not Drive.Deviceid="P:" then
Set Objfso=createobject("Scripting.filesystemobject")
If objfso.Fileexists("drive.deviceid\NO_SMS_ON_DRIVE.SMS") then
Else
Set smsondrive=objfso.createtextfile(drive.deviceid & "\NO_SMS_ON_DRIVE.SMS",True)
smsondrive.close
End If
End If
Next
End Sub
'==========================Creation of NO_SMS_ON_DRIVE.SMS=====================
答案 0 :(得分:1)
您更有可能在第57行中收到语法错误。您定义了Sub DeleteSbukeys
而没有End Sub
且VBScript不允许嵌套过程定义。
...
Sub DeleteSubkeys(HKEY_LOCAL_MACHINE, strKeyPathm)
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPathm, arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys HKEY_LOCAL_MACHINE, strKeyPathm & "\" & strSubkey
Next
End If
objRegistry.DeleteKey HKEY_LOCAL_MACHINE, strKeyPathm
Call Nosmsondrive()
Call Removalofflders()
objRegistry.DeleteKey HKEY_CURRENT_USER,strKeyPath
'<-- "End Sub" missing here
Sub ccmsetup()
Set wshshell=wscript.createobject("wscript.shell")
Wscript.echo "Please Wait while SCCM 2007 client is getting uninstalled"
...