Checking Different sReturn Codes for JoinDomain

email me

* Recommended: add these to a case statement

sReturn = oCmp.JoinDomainOrWorkgroup(strDomain, strPW, strUser, NULL, JOIN_DOMAIN+ACCT_CREATE)
'msgbox "ReturnValue = " & CStr(sReturn)

'successfully joined
if sReturn = 0 then self.close()

'access denied
if sReturn = 5 then msgbox "Access Denied!"

'cannot find network
if sReturn = 53 then msgbox "Network path not found!"

'logon failure
if sReturn = 1326 then msgbox "Invalid credentials!"

'domain contact issue
if sReturn = 1355 then msgbox "Domain cannot be contacted!"

'already joined
if sReturn = 2691 then 
msgbox "Computer already joined!"
self.close()
end if


''''''' Case Statement Example '''''''

'Select Case sReturn

'Case 0 Status = "Success"

'Case 2 Status = "Missing OU"

'Case 5 Status = "Access denied"

'Case 53 Status = "Network path not found"

'Case 87 Status = "Parameter incorrect"

'Case 1326 Status = "Logon failure, user or pass"

'Case 1355 Status = "Domain can not be contacted"

'Case 1909 Status = "User account locked out"

'Case 2224 Status = "Computer Account already exists"

'Case 2691 Status = "Already joined"

'Case Else Status = "UNKNOWN ERROR " & sReturn

' Show Status
'WScript.Echo "Join domain status: " & Status

'End Select

Check Workstation Status in AD

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)

Set colComputers = objWMIService.ExecQuery _
(“Select DomainRole from Win32_ComputerSystem”)

For Each objComputer in colComputers
Select Case objComputer.DomainRole
Case 0
strComputerRole = “Standalone Workstation”
Wscript.Echo “This is NOT on the domain. Reload [HTA]”
Case 1
strComputerRole = “Member Workstation”
Wscript.Echo “This is on the domain. Exit [HTA]”
End Select
Next

email me

Scanning Reg Key Types

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003

Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7

‘ Chose computer name, registry tree and key path

strComputer = “.” ‘ Use . for current machine
hDefKey = HKEY_LOCAL_MACHINE
strKeyPath = “SOFTWARE\Microsoft\Cryptography\Defaults\Provider”

‘ Connect to registry provider on target machine with current user

Set oReg = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\default:StdRegProv”)

‘ Enum the subkeys of the key path we’ve chosen

oReg.EnumKey hDefKey, strKeyPath, arrSubKeys

For Each strSubkey In arrSubKeys

‘ Show the subkey

wscript.echo strSubkey

‘ Show its value names and types

strSubKeyPath = strKeyPath & “\” & strSubkey
oReg.EnumValues hDefKey, strSubKeyPath, arrValueNames, arrTypes

For i = LBound(arrValueNames) To UBound(arrValueNames)
strValueName = arrValueNames(i)
Select Case arrTypes(i)

‘ Show a REG_SZ value

Case REG_SZ
oReg.GetStringValue hDefKey, strSubKeyPath, strValueName, strValue
wscript.echo ” ” & strValueName & ” (REG_SZ) = ” & strValue

‘ Show a REG_EXPAND_SZ value

Case REG_EXPAND_SZ
oReg.GetExpandedStringValue hDefKey, strSubKeyPath, strValueName, strValue
wscript.echo ” ” & strValueName & ” (REG_EXPAND_SZ) = ” & strValue

‘ Show a REG_BINARY value

Case REG_BINARY
oReg.GetBinaryValue hDefKey, strSubKeyPath, strValueName, arrBytes
strBytes = “”
For Each uByte in arrBytes
strBytes = strBytes & Hex(uByte) & ” ”
Next
wscript.echo ” ” & strValueName & ” (REG_BINARY) = ” & strBytes

‘ Show a REG_DWORD value

Case REG_DWORD
oReg.GetDWORDValue hDefKey, strSubKeyPath, strValueName, uValue
wscript.echo ” ” & strValueName & ” (REG_DWORD) = ” & CStr(uValue)

‘ Show a REG_MULTI_SZ value

Case REG_MULTI_SZ
oReg.GetMultiStringValue hDefKey, strSubKeyPath, strValueName, arrValues
wscript.echo ” ” & strValueName & ” (REG_MULTI_SZ) =”
For Each strValue in arrValues
wscript.echo ” ” & strValue
Next

End Select
Next

Next

email me

Scanning and Changing Reg Keys

Setting Dynamic Sound Settings on the HP 9470 Laptop.

This changes/updates the sound settings for the HP Laptop that uses random GUIDs in the registry.

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003

Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7

strComputer = “.”
hDefKey = HKEY_LOCAL_MACHINE

Set oReg = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & strComputer & “\root\default:StdRegProv”)

‘THIS CHANGES THE FIRST SET OF KEYS
strKeyPath = “SOFTWARE\IDT\Apo\LFX\MicIn4\Presets\_Initial\SpeexNS”

oReg.EnumKey hDefKey, strKeyPath, arrSubKeys
on error resume next
For Each strSubkey In arrSubKeys
strSubKeyPath = strKeyPath & “\” & strSubkey
oReg.EnumValues hDefKey, strSubKeyPath, arrValueNames, arrTypes

For i = LBound(arrValueNames) To UBound(arrValueNames)
strValueName = arrValueNames(i)
Select Case arrTypes(i)

Case REG_DWORD
oReg.GetDWORDValue hDefKey, strSubKeyPath, strValueName, uValue
‘wscript.echo ” ” & strValueName & ” (REG_DWORD) = ” & CStr(uValue)
‘wscript.echo uValue
if uValue = 0 then
newValue = 1
oReg.SetDWORDValue hDefKey, strSubKeyPath, strValueName, newValue
end if
End Select
Next

Next

‘THIS CHANGES THE SECOND SET OF KEYS
strKeyPath = “SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio\Render”

Dim strGUID
oReg.EnumKey hDefKey, strKeyPath, arrSubKeys
on error resume next
For Each strSubkey In arrSubKeys
strSubKeyPath = strKeyPath & “\” & strSubkey & “\” & “Properties”
oReg.EnumValues hDefKey, strSubKeyPath, arrValueNames, arrTypes

For i = LBound(arrValueNames) To UBound(arrValueNames)
strValueName = arrValueNames(i)
Select Case arrTypes(i)
Case REG_SZ
oReg.GetStringValue hDefKey, strSubKeyPath, strValueName, strValue
‘wscript.echo ” ” & strValueName & ” (REG_SZ) = ” & strValue
if strValue = “Speakers / HP” then
strGUID = strSubKeyPath
end if
End Select
Next

Next

strKeyPath = strGUID

oReg.EnumKey hDefKey, strKeyPath, arrSubKeys
on error resume next
For Each strSubkey In arrSubKeys

strSubKeyPath = strKeyPath & “\” & strSubkey
oReg.EnumValues hDefKey, strSubKeyPath, arrValueNames, arrTypes

For i = LBound(arrValueNames) To UBound(arrValueNames)
strValueName = arrValueNames(i)
Select Case arrTypes(i)

Case REG_DWORD
oReg.GetDWORDValue hDefKey, strSubKeyPath, strValueName, uValue
‘wscript.echo ” ” & strValueName & ” (REG_DWORD) = ” & CStr(uValue)
if uValue = 0 then
newValue = 1
oReg.SetDWORDValue hDefKey, strSubKeyPath, strValueName, newValue
end if
End Select
Next

Next

Wscript.quit(0)

email me

Set Registry Permissions

‘ Create a temp file with the script that regini.exe will use

set oFSO = CreateObject(“Scripting.FileSystemObject”)
strFileName = oFSO.GetTempName
set oFile = oFSO.CreateTextFile(strFileName)
oFile.WriteLine “HKEY_LOCAL_MACHINE\Software\Classes\AlejaCMaTypelib [1 5 7 11 17]”
oFile.WriteLine “HKEY_LOCAL_MACHINE\Software\AlejaCMaCo\AlejaCMaApp [1 5 7 11 17]”
oFile.Close

‘ Change registry permissions with regini.exe

set oShell = CreateObject(“WScript.Shell”)
oShell.Run “regini ” & strFileName, 8, true

‘ Delete temp file

oFSO.DeleteFile strFileName

WScript.Echo “Done!”

email me

Installing Google Chat Plugin into your Image

Add this to your current Windows 7 image. This allows the Google Chat Plugin to be installed to each new user profile.

@echo off
rem place default.cmd file here
rem C:\users\default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

rem place googletalkpluginaccel.msi here
rem C:\Windows\Installer\

Title Administrative Installer by Eddie Jackson
color 0a

cls
Echo Installing Google Chat Plugin…
c:\windows\system32\msiexec.exe /i “C:\Windows\Installer\googletalkpluginaccel.msi” /qn /norestart

cls
echo Google Plugin Installed!
c:\windows\system32\ping.exe -n 4 127.0.0.1>nul

rem
ADD FUTURE ITEMS HERE

cls
echo Exiting now…
c:\windows\system32\ping.exe -n 4 127.0.0.1>nul

rem removes the default.cmd from the current user logged in
del /q “C:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\default.cmd”
exit /b 0

email me

Set black wall paper to the new build through VB Script

Option Explicit
‘On Error Resume Next

Dim WshShell
Dim OsType
Dim WshShell, objFSO, PROG, orgexe, newexe,c,value
Set WshShell = CreateObject(“WScript.Shell”)

OsType = WshShell.RegRead(“HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE”)

If OsType = “x86″ then

WshShell.Regwrite “HKEY_CURRENT_USER\Control Panel\Desktop\ScreenSaveActive”, “1″, “REG_SZ”
WshShell.Regwrite “HKEY_CURRENT_USER\Control Panel\Desktop\ScreenSaverIsSecure”, “1″, “REG_SZ”
WshShell.Regwrite “HKEY_CURRENT_USER\Control Panel\Desktop\ScreenSaveTimeOut”, “300″, “REG_SZ”
WshShell.Regwrite “HKEY_CURRENT_USER\Control Panel\Desktop\SCRNSAVE.EXE”, “C:\Windows\screensaver\Blktxt3.scr”, “REG_SZ”

WshShell.Run “Cscript.exe C:\Program Files\WallPaperFiles\ZCGSetWallpaper.wsf”

WshShell.Run “Cscript.exe C:\Program Files\WallPaperFiles\ZCGChangeBackColor.wsf”

elseif OsType = “AMD64″ Then

WshShell.Regwrite “HKEY_CURRENT_USER\Control Panel\Desktop\ScreenSaveActive”, “1″, “REG_SZ”
WshShell.Regwrite “HKEY_CURRENT_USER\Control Panel\Desktop\ScreenSaverIsSecure”, “1″, “REG_SZ”
WshShell.Regwrite “HKEY_CURRENT_USER\Control Panel\Desktop\ScreenSaveTimeOut”, “300″, “REG_SZ”
WshShell.Regwrite “HKEY_CURRENT_USER\Control Panel\Desktop\SCRNSAVE.EXE”, “C:\Windows\screensaver\Blktxt3.scr”, “REG_SZ”

WshShell.Run “Cscript.exe C:\Program Files\WallPaperFiles\ZCGSetWallpaper.wsf”

WshShell.Run “Cscript.exe C:\Program Files\WallPaperFiles\ZCGChangeBackColor.wsf”

end If
set WshShell = Nothing
Set objFSO = Nothing

email me

How to determine whether a computer is VM or Physical through VB Script

strComputer = “.”

wscript.echo getMachineType(strComputer)

function GetMachineType(strComputer)
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2″)

Set colSettings = objWMIService.ExecQuery _
(“Select * from Win32_ComputerSystem”)

For Each objComputer in colSettings
strType = objComputer.Manufacturer
Next
if lcase(left(strType,6))=”vmware” then
GetMachineType=”V” ‘Virtual VMWare Box.
else
GetMachineType=”P” ‘Physical Machine
end if
end function

email me

Script to Put User Picture in Active Directory

Function PictureToAD(szADSOBJ, szFileName)
Dim objUser, bytesRead, adoStreamRead
Const adTypeBinary = 1
Set adoStreamRead = CreateObject(“ADODB.Stream”)
adoStreamRead.Type = adTypeBinary
adoStreamRead.Open
adoStreamRead.LoadFromFile szFileName
bytesRead = adoStreamRead.Read()
adoStreamRead.Close
Set objUser = GetObject(szADSOBJ)
objUser.Put “thumbnailPhoto”, bytesRead
objUser.SetInfo
End Function

email me