Following is the DisableMappedPrinter script used in the previous example.
Dim Octet,ObjNetwork, WshShell, ViewClientIP, UserName, WhitePaper, IFUserInWhitePaper
Set WshShell = CreateObject("WScript.Shell")
ViewClientIP = WshShell.RegRead("HKCU\Volatile Environment\ViewClient_IP_Address")
UserName = WshShell.RegRead("HKCU\Volatile Environment\UserName")
WhitePaper = "C:\temp\WhitePaper.txt"
ServiceName="'TPAutoConnSvc'"
strCmd="""C:\Program Files\Common Files\ThinPrint\TPAutoConnect.exe"" -d"
Octet = Split(ViewClientIP,".")
IFUserInWhitePaper = VerifyUserInWhitePaper(WhitePaper,UserName)
Default=WshShell.RegRead("HKLM\Software\Policies\VMware, Inc.\VMware VDM\Agent\")
' WScript.Echo "First IP Octet: " & Octet(0)
' WScript.Quit
on Error Resume Next
Set oLocator = WScript.CreateObject("WbemScripting.SWbemLocator")
Set oService = oLocator.ConnectServer
Set oClassSet = oService.ExecQuery("Select * From Win32_Service Where Name=" & ServiceName)
For Each oClass In oClassSet
' Assuming IP address beginning with Octet 1 or 10 is internal.
' If user is in white paper, set printer and USB enabled.
' Expecting StopService/StopService fails if it's already stopeed/started.
' Ignorring the error in this case
if not(Octet(0) = 1 Or Octet(0) = 10 Or IFUserInWhitePaper) Then
lRet = WshShell.Run(strCmd,0,True)
lRet = oClass.StopService()
' WScript.Echo "Stopped Service : Return Value:" & lRet
WshShell.RegWrite "HKLM\Software\Policies\VMware, Inc.\VMware VDM\Agent\USB\",Default
WshShell.RegWrite "HKLM\Software\Policies\VMware, Inc.\VMware VDM\Agent\USB\ExcludeAllDevices","true","REG_DWORD"
Else
lRet = oClass.StartService()
'WScript.Echo "Started Service : Return Value:" & lRet
WshShell.RegDelete "HKLM\Software\Policies\VMware, Inc.\VMware VDM\Agent\USB\ExcludeAllDevices"
End If
Next
Set WshShell = Nothing
Set ObjNetwork = Nothing
Set oClassSet = Nothing
Set oClass = Nothing
Set oService = Nothing
Set oLocator = Nothing
Function VerifyUserInWhitePaper(filePath,userName)
dim fso,fread,str,strarry,linestr
set fso=createobject("scripting.filesystemobject")
set fread=fso.opentextfile(filePath,1)
str=fread.readall
fread.close
if str="" then
wscript.echo "file have not any content"
wscript.quit
end if
strarry=split(str,vbcrlf)
for each linestr in strarry
if linestr=userName then
VerifyUserInWhitePaper=True
Exit for
else
VerifyUserInWhitePaper=False
end if
next
set fso=nothing
End Function