2015-07-19 45 views
0

我运行以下脚本,卸载sccm 2007客户端,卸载wds,webdav,删除过时的注册表项和文件夹,然后在除p驱动器之外的所有驱动器上创建.sms文件,我想要该脚本按顺序执行操作,并应从重新启动后从停止的位置进行选择,但在拨打ccmsetup后出现压缩错误。我哪里错了?我们可以在执行脚本的过程中调用子程序吗?获得compliation serror,语法错误

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===================== 
+1

你应该至少也分享你得到的确切的错误。 – planetmaker

+0

补充错误(59,1)这是ccmsetup子,最后它说的语法错误 – Raghava

+0

从一个不同的网站,我知道,我不能从脚本的中间运行Sub例程。已经运行的脚本应该在子运行之前关闭..是真的吗? – Raghava

回答

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" 
... 
+0

非常感谢Ansgar .. :)它工作。 – Raghava

+0

@Raghava不客气。如果您发现它解决了您的问题,请考虑[接受答案](http://meta.stackexchange.com/a/5235)。 –