Month: February 2017
VBScript – Is User a Member of Group
Option Explicit Dim arrMemberNames(), initialSize, i, strHolder, objADGroup Dim strMemberName, strADUser, objADUser, strBool, objNetwork, strComputerUser Dim strGroupMember initialSize = 0 strBool = "FALSE" Set objNetwork = CreateObject("Wscript.Network") 'SET AD GROUP Set objADGroup = GetObject("LDAP://CN=TheGroupName,DC=DomainName,DC=com") 'SET USER strComputerUser = objNetwork.UserName strComputerUser = LCase(strComputerUser) 'DETERMINE WHETHER COMPUTER USER IS IN GROUP For Each strADUser in objADGroup.Member Set objADUser = GetObject("LDAP://" & strADUser) strGroupMember = LCase(objADUser.sAMAccountName) if strComputerUser = strGroupMember then strBool = "TRUE" end if ReDim Preserve arrMemberNames(initialSize) arrMemberNames(initialSize) = objADUser.CN initialSize = initialSize + 1 Next If strBool = "TRUE" then msgbox "User was found in group!" 'CLEAR SESSION initialSize = "" i = "" strHolder = "" objADGroup = "" strMemberName = "" strADUser = "" objADUser = "" strBool = "" 'EXIT WScript.Quit(0)
PowerShell – Is User a Member of Group
Import-Module ActiveDirectory $user = "$env:UserName" #[System.Security.Principal.WindowsIdentity]::GetCurrent().Name #$(whoami) #$(Get-WMIObject -class Win32_ComputerSystem | select username).username if ((Get-ADUser $User -Properties memberof).memberof -like "CN=TheGroupName*") { $true } Else { $false }
Screenshot
Notes
PowerShell/VBScript – Return Members from AD Group
VBScript Method
Option Explicit Dim arrMemberNames(), initialSize, i, j, strHolder, objADGroup Dim strMemberName, strADUser, objADUser initialSize = 0 Set objADGroup = GetObject("LDAP://CN=TheGroupName,OU=TheOU,DC=YourDomain,DC=com") For Each strADUser in objADGroup.Member Set objADUser = GetObject("LDAP://" & strADUser) 'msgbox strADUser ReDim Preserve arrMemberNames(initialSize) arrMemberNames(initialSize) = objADUser.CN initialSize = initialSize + 1 Next For i = (UBound(arrMemberNames) - 1) to 0 Step -1 For j= 0 to i If UCase(arrMemberNames(j)) > UCase(arrMemberNames(j+1)) Then strHolder = arrMemberNames(j+1) arrMemberNames(j+1) = arrMemberNames(j) arrMemberNames(j) = strHolder End If Next Next For Each strMemberName in arrMemberNames Wscript.Echo strMemberName Next initialSize = "" i = "" j = "" strHolder = "" objADGroup = "" strMemberName = "" strADUser = "" objADUser = ""
PowerShell Method
Import-Module ActiveDirectory Get-AdGroupMember -identity "GroupNameHere" | select-object "samaccountname"
PowerShell – Return Product Key and/or Save to Text File
Function Get-ProductKey { Clear-Host $HKLM = 2147483650 $ComputerName = $env:COMPUTERNAME $MSRegPath = "Software\Microsoft\Windows NT\CurrentVersion" $DigitalID = "DigitalProductId" $wmi = [WMIClass]"\\$ComputerName\root\default:stdRegProv" #Return MS Reg Value - used in translation $WMIObject = $wmi.GetBinaryValue($HKLM,$MSRegPath,$DigitalID) [Array]$DigitalValue = $WMIObject.uValue #If value is returned If($DigitalValue) { #Perform translation $TranslatedResult = ConvertTokey $DigitalValue $OperatingSystem = (Get-WmiObject "Win32_OperatingSystem" | select Caption).Caption If($OperatingSystem -match "Microsoft Windows 8" -or $OperatingSystem -match "Microsoft Windows 10") { if($TranslatedResult) { [string]$ProductKey ="$TranslatedResult" $ProductKey #Save Windows info to a file $UserChoice = UserOption If( $UserChoice -eq 0 ) { $TextFilePath = "C:\Users\"+$env:USERNAME+"\Desktop" New-Item -Path $TextFilePath -Name "ProductKey.txt" -Value $ProductKey -ItemType File -Force | Out-Null } } } } } #User Option Function UserOption { $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes","" $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No","" $UserChoices = [System.Management.Automation.Host.ChoiceDescription[]]($yes,$no) $MsgCaption = "Confirm" $Msg = " Save product key to ProductKey.txt on Desktop?" $TranslatedResult = $Host.UI.PromptForChoice($MsgCaption,$Msg,$UserChoices,0) $TranslatedResult } #Perform translation Function ConvertToKey($Key) { $Keyoffset = 52 $isWin8 = [int]($Key[66]/6) -band 1 $HF7 = 0xF7 $Key[66] = ($Key[66] -band $HF7) -bOr (($isWin8 -band 2) * 4) $i = 24 [String]$Chars = "BCDFGHJKMPQRTVWXY2346789" do { $Cur = 0 $X = 14 Do { $Cur = $Cur * 256 $Cur = $Key[$X + $Keyoffset] + $Cur $Key[$X + $Keyoffset] = [math]::Floor([double]($Cur/24)) $Cur = $Cur % 24 $X = $X - 1 }while($X -ge 0) $i = $i- 1 $KeyOutput = $Chars.SubString($Cur,1) + $KeyOutput $last = $Cur }while($i -ge 0) $Keypart1 = $KeyOutput.SubString(1,$last) $Keypart2 = $KeyOutput.Substring(1,$KeyOutput.length-1) if($last -eq 0 ) { $KeyOutput = "N" + $Keypart2 } else { $KeyOutput = $Keypart2.Insert($Keypart2.IndexOf($Keypart1)+$Keypart1.length,"N") } $a = $KeyOutput.Substring(0,5) $b = $KeyOutput.substring(5,5) $c = $KeyOutput.substring(10,5) $d = $KeyOutput.substring(15,5) $e = $KeyOutput.substring(20,5) $keyproduct = $a + "-" + $b + "-"+ $c + "-"+ $d + "-"+ $e $keyproduct } Get-ProductKey
Batch – Resetting Windows Update Agent
This script is to be used to repair the Windows Update Agent. Note, you must run it as admin or deploy in the System Account.
@echo off title Reset Windows Update Agent cls color 0a echo Stopping Windows Update services… ping -n 4 127.0.0.1>nul net stop wuauserv net stop bits net stop appidsvc net stop cryptsvc net stop ccmexec echo Success! echo. ping -n 4 127.0.0.1>nul echo Checking services… ping -n 4 127.0.0.1>nul sc query wuauserv | findstr /I /C:”STOPPED” if %errorlevel% NEQ 0 goto END sc query bits | findstr /I /C:”STOPPED” if %errorlevel% NEQ 0 goto END sc query appidsvc | findstr /I /C:”STOPPED” if %errorlevel% NEQ 0 sc query appidsvc | findstr /I /C:”OpenService FAILED 1060? if %errorlevel% NEQ 0 goto END sc query cryptsvc | findstr /I /C:”STOPPED” if %errorlevel% NEQ 0 goto END sc query ccmexec | findstr /I /C:”STOPPED” if %errorlevel% NEQ 0 sc query ccmexec | findstr /I /C:”OpenService FAILED 1060? if %errorlevel% NEQ 0 goto END echo Success! echo. ping -n 4 127.0.0.1>nul echo Deleting AU cache folder and log file… ping -n 4 127.0.0.1>nul del /f /q “%ALLUSERSPROFILE%\Application Data\Microsoft\Network\Downloader\qmgr*.dat” del /f /s /q %SystemRoot%\SoftwareDistribution\*.* del /f /s /q %SystemRoot%\system32\catroot2\*.* del /f /q %SystemRoot%\WindowsUpdate.log Data\Microsoft\Network\Downloader\qmgr*.dat” echo Success! echo. ping -n 4 127.0.0.1>nul echo Re-registering DLL files… ping -n 4 127.0.0.1>nul cd /d %WinDir%\system32 regsvr32.exe /s atl.dll regsvr32.exe /s urlmon.dll regsvr32.exe /s mshtml.dll regsvr32.exe /s shdocvw.dll regsvr32.exe /s browseui.dll regsvr32.exe /s jscript.dll regsvr32.exe /s vbscript.dll regsvr32.exe /s scrrun.dll regsvr32.exe /s msxml.dll regsvr32.exe /s msxml3.dll regsvr32.exe /s msxml6.dll regsvr32.exe /s actxprxy.dll regsvr32.exe /s softpub.dll regsvr32.exe /s wintrust.dll regsvr32.exe /s dssenh.dll regsvr32.exe /s rsaenh.dll regsvr32.exe /s gpkcsp.dll regsvr32.exe /s sccbase.dll regsvr32.exe /s slbcsp.dll regsvr32.exe /s cryptdlg.dll regsvr32.exe /s oleaut32.dll regsvr32.exe /s ole32.dll regsvr32.exe /s shell32.dll regsvr32.exe /s initpki.dll regsvr32.exe /s wuapi.dll regsvr32.exe /s wuaueng.dll regsvr32.exe /s wuaueng1.dll regsvr32.exe /s wucltui.dll regsvr32.exe /s wups.dll regsvr32.exe /s wups2.dll regsvr32.exe /s wuweb.dll regsvr32.exe /s qmgr.dll regsvr32.exe /s qmgrprxy.dll regsvr32.exe /s wucltux.dll regsvr32.exe /s muweb.dll regsvr32.exe /s wuwebv.dll echo Success! echo. ping -n 4 127.0.0.1>nul echo Removing WSUS Client ID… ping -n 4 127.0.0.1>nul REG DELETE “HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate” /v AccountDomainSid /f REG DELETE “HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate” /v PingID /f REG DELETE “HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate” /v SusClientId /f echo Success! echo. ping -n 4 127.0.0.1>nul echo Resetting Winsock and WinHTTP Proxy… ping -n 4 127.0.0.1>nul netsh winsock reset proxycfg.exe -d netsh winhttp reset proxy echo Success! echo. ping -n 4 127.0.0.1>nul echo Starting services… ping -n 4 127.0.0.1>nul net start ccmexec net start cryptsvc net start appidsvc net start bits net start wuauserv echo Success! echo. ping -n 4 127.0.0.1>nul echo Deleting all BITS jobs… ping -n 4 127.0.0.1>nul bitsadmin.exe /reset /allusers echo Success! echo. ping -n 4 127.0.0.1>nul echo Forcing AU discovery… ping -n 4 127.0.0.1>nul wuauclt /resetauthorization /detectnow echo Success! echo. ping -n 4 127.0.0.1>nul :END echo Windows Update Agent has been reset! pause exit /b 0
PowerShell – Return Product Key
This is how you return the product key for your computer using PowerShell
$Computer = $Env:Computername $TranslationMapping="BCDFGHJKMPQRTVWXY2346789" $MSRegKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$Computer) $value = $MSRegKey.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('DigitalProductId4')[0x34..0x42] $ProductKeyOutput = "" for ($i = 24; $i -ge 0; $i--) { $r = 0 for ($j = 14; $j -ge 0; $j--) { $r = ($r * 256) -bxor $value[$j] $value[$j] = [math]::Floor([double]($r/24)) $r = $r % 24 } $ProductKeyOutput = $TranslationMapping[$r] + $ProductKeyOutput if (($i % 5) -eq 0 -and $i -ne 0) { $ProductKeyOutput = "-" + $ProductKeyOutput } } clear-host write-host "" "Product Key: " + $ProductKeyOutput write-host ""
Adobe Connect No Longer Automated in Chrome
Here is a problem (unresolved as of now) that I’m having with the Adobe Connect plugin in the Chrome browser. I used to be able to deploy it silently, and it would not prompt the end-user to complete installation. Now, however, the end-user receives multiple pop ups. I have no issues in IE or Firefox.
In testing, this is what I get
What the end-user is seeing
I’ve contacted Google and Adobe thus far…nothing yet. I used installers from here:
https://www.adobe.com/support/connect/downloads-updates.html
http://www.adobe.com/go/adobeconnect_addinchecker
http://blogs.adobe.com/connectsupport/installing-add-in-for-all-user-profiles/
I’ll keep you posted on what I find out.
* Update 02/09/2017
Final word from Adobe and Google, there is no way to suppress the pop ups.
Notes
If I copy the Google preference file from a reference machine, it does work…of course, there is no good way of deploying that file without wiping out the end-user’s personal Chrome preferences.
And, yes, I did try manually adding the plugin to C:\Users\%username%\AppData\Roaming\Macromedia\Flash Player\macromedia.com\bin\connectaddin
Batch – Verify Returned Values are Numbers
So, this came about because I was looking at an old script that uses manage-bde.exe to return the Bitlocker. No big deal,really, but…apparently someone forgot to actually verify the returned value was at least numbers.
This was the command
for /f “skip=5 tokens=1 delims=Password ” %%h in (‘”c:\windows\system32\manage-bde.exe -protectors -get c:”‘) do set BitPass=%%h
Which returns something like this
123456-123456-123456-123456-123456-123456-123456-123456
What I added was this
SET “var=”&for /f “delims=0123456789-” %%i in (“%BitPass%”) do set var=%%i
if defined var (exit)
What this does is compare BitPass to the specified delimiters, if it matches…it continues; if not, it exists.
Skype 7.31.80.104 Silent Install – Multiple Methods
Command
SkypeSetupFull.exe /VERYSILENT /SP- /NOCANCEL /NORESTART /SUPPRESSMSGBOXES /NOLAUNCH
LANDesk Wrapper – Batch
@echo on cls title Skype Installer :: this is the LANDesk 32bit wrapper – to be compiled :: launch splash screen Echo Installing Skype… if exist C:\Progra~2\LANDesk\LDClient\sdmcache\apps\Microsoft\Skype\7.31.80.104\progress.hta ( start “” C:\Progra~2\LANDesk\LDClient\sdmcache\apps\Microsoft\Skype\7.31.80.104\progress.hta ) :: install Skype silently “C:\Progra~2\LANDesk\LDClient\sdmcache\apps\Microsoft\Skype\7.31.80.104\SkypeSetupFull.exe” /VERYSILENT /SP- /NOCANCEL /NORESTART /SUPPRESSMSGBOXES /NOLAUNCH :: delete exe del /q “C:\Progra~2\LANDesk\LDClient\sdmcache\apps\Microsoft\Skype\7.31.80.104\SkypeSetupFull.exe” :: kill splash %windir%\system32\taskkill.exe /f /im mshta.exe :: delete progress animation files del /q “C:\Progra~2\LANDesk\LDClient\sdmcache\apps\Microsoft\Skype\7.31.80.104\progress.*” :: delete this sequence file del /q “C:\Progra~2\LANDesk\LDClient\sdmcache\apps\Microsoft\Skype\7.31.80.104\sequence.cmd” exit /b 0
LANDesk Wrapper – VBScript
on error resume next Dim CommandLine, CurrentFolder, objfso, Path64, Path86, LDFolder, objShell set objShell = CreateObject("WScript.Shell") Set objfso = CreateObject("Scripting.FileSystemObject") 'Determine if 32 or 64 bit LDClient is installed Path64 = "C:\Progra~2" Path86 = "C:\Progra~1" LDFolder = "\LANDesk\LDClient\sdmcache\apps\Microsoft\Skype\7.31.80.104" If (objfso.FolderExists(Path64 & LDFolder)) Then CurrentFolder = Path64 & LDFolder Else CurrentFolder = Path86 & LDFolder End If 'kills the progress bar objShell.Run "taskkill.exe /f /im mshta.exe",0,False WScript.Sleep 2000 'launches the progress bar objShell.Run "%comspec% /c " & CurrentFolder & "\progress.hta",0,False 'set command line operation CommandLine = "%comspec% /c " & chr(34) & CurrentFolder & "\SkypeSetupFull.exe" & Chr(34) & " /VERYSILENT /SP- /NOCANCEL /NORESTART /SUPPRESSMSGBOXES /NOLAUNCH" 'launch operation objShell.Run CommandLine,0,True WScript.Sleep 2000 'kills the progress bar objShell.Run "taskkill.exe /f /im mshta.exe",0,false 'clear session CommandLine = "" CurrentFolder = "" Path64 = "" Path86 = "" LDFolder = "" objfso = "" objShell = "" WScript.Quit(0)
Elevated Wrapper – should be compiled
On Error Resume Next Dim CommandLine, strTemp, objRegistry, strComputer, regValue, regValueName, regPath, objShell, strDate, BuildVersion, strComputerName, UName, PWord Const HKEY_LOCAL_MACHINE = &H80000002 AppName = "Skype" BuildVersion = "7.31.80.104" 'there are better ways to elevate processes 'see Microsoft's SecureString and ProcessStartInfo UName = "administrator" PWord = "TheAdminPassword" strTemp = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%temp%" & "\" & AppName) strComputer = "." strComputerName = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%computername%") 'set event log command CreateEventLog = "EVENTCREATE /T INFORMATION /L Application /ID 777 /d " & Chr(34) & "Software Packaging Engineer: " & AppName & " " & BuildVersion & " package installation" Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") set objShell = CreateObject("WScript.Shell") SetStringValue = REG_SZ 'set command line operation CommandLine = strTemp & "\cpau.exe -u " & strComputerName &"\" & UName & " -p " & PWord & " -ex " & chr(34) & strTemp & "\SkypeSetupFull.exe /VERYSILENT /SP- /NOCANCEL /NORESTART /SUPPRESSMSGBOXES /NOLAUNCH" & chr(34) & " -lwop -wait" 'kills the progress bar 'objShell.Run "taskkill.exe /f /im mshta.exe",0,false WScript.Sleep 2000 'launches the progress bar 'objShell.Run strTemp & "\progress.hta",9,false 'Launch operation with event logging objShell.Run CreateEventLog & " STARTED" & Chr(34),0,True objShell.Run CommandLine,0,True objShell.Run CreateEventLog & " COMPLETED" & Chr(34),0,True WScript.Sleep 2000 'Stamp registry for tracking strDate = chr(34) & NOW & chr(34) regValueName = "Timestamp" regPath = "SOFTWARE\TRACKER\" & AppName & "\" & BuildVersion 'create main key objRegistry.CreateKey HKEY_LOCAL_MACHINE, regPath 'set value objRegistry.SetStringValue HKEY_LOCAL_MACHINE,regPath, regValueName, strDate WScript.Sleep 2000 'kills the progress bar 'objShell.Run "taskkill.exe /f /im mshta.exe",0,false 'Clear session CommandLine = "" strTemp = "" objRegistry = "" strComputer = "" regValue = "" regValueName = "" regPath = "" objShell = "" strDate = "" AppName = "" BuildVersion = "" strComputerName UName = "" PWord = "" WScript.Quit(0)