VBScript: Search remote registry to return SID and mapped share drives - vbscript

I'm looking for some help creating script that would search for username in
ProfileImagePath string in Remote_Machine\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21*
and would get parent directory-the SID S-1-5-21*, store it in memory and later use it to output keys under
Remote_machine\HKEY_USERS*SID*\Software\Microsoft\Windows\CurrentVersion\Explorer\MountPoints2.
I was only able to find script:
Set objNetwork = CreateObject("Wscript.Network")
strComputerName = InputBox("Please input PC name:","")'objNetwork.ComputerName
strLogonUser = objNetwork.UserName
Domaccount = trim(cstr(InputBox("Please input Domain User Account:","Type User_
Account")))
strDomain = "Dom"
Set objWMIService = GetObject("winmgmts:\\" & strComputerName & "\root\cimv2")
Set objAccount = objWMIService.Get ("Win32_UserAccount.Name='" & Domaccount &_
"',Domain='" & strDomain & "'")
Wscript.Echo objAccount.SID
but that one does not work all the time - I get SWbemServicesEx: Not found
and I think it uses different method than search. Moreover it does only first part of my request.
Can anyone help a brother out? :)

I am not sure to have understood your exact problem, anyway this hotfix released by Microsoft has been useful to me in a similar situation:
http://support.microsoft.com/kb/2465990

Related

How to get the full computer name using Test Complete

How to get the full computer name using Test Complete
For example,
Computer Name : RAMAKRISHNA
Full Computer Name : RAMAKRISHNA.XYZ.COM
Domain Name : XYZ.COM
Using TestComplete, I have tried the following:
log.Message sys.HostName 'Gives "RAMAKRISHNA"
log.Message sys.DomainName 'Gives "XYZ"
Here, I am missing to get ".COM" using TestComplete
Please help me to get the full computer like RAMAKRISHNA.XYZ.COM
You can do this using WMI.
Sub Test
Log.Message getFullPCName
End Sub
Function getFullPCName
Set cSystem = WMI.Service.InstancesOf("Win32_ComputerSystem").ItemIndex(0)
getFullPCName = cSystem.Name & "." & cSystem.Domain
End Function
Windows Management Instrumentation technology provides ways to manage Windows settings and operations. You can use the Win32_ComputerSystem WMI class to get information on the system. TestComplete provides an easy way to work with WMI using the corresponding object. Find more information in the WMI Object help topic.
Try this if it helps:
Set wshShell = CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
WScript.Echo "Computer Name: " & strComputerName & "." & GetDomainName
Function GetDomainName()
Dim Info
Set Info = CreateObject("AdSystemInfo")
GetDomainName = Info.DomainDNSName
End Function

vbScript that Checks NetworkAdapter Config and updates URL if it detects change

Ok... everyone here seems to be way more educated about this stuff than I. But I've been at this for 2 days straight and I've gone at it from all kinds directions.
Goal:
Have a script check the IP address of local pc. At some time (thinking 5 minutes) recheck the IP address again. Compare the two and if there is a change execute a command silently.
I realize that I can not just get the IP address as I'll get the entire state using winmgmts and I'm ok with that. Really it's just to keep an eye on whether or not the state changes in general. The line of code is to access a URL which will update my FreeDNS incase the IP changes. For whatever reason, none of the programs offered have been working. One even crashes .Net Framework.
Knowing that I'm an utter noob (and thank you for reading this far!) here's what my crazy broken and utterly bizarre code looks like. Any assistance would be divine and I apologize
Dim firstSet, secondSet
Set objWMIService = GetObject("winmgmts:")
Set FirstIP = objWMIService.ExecQuery("SELECT * FROM " & "Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
Set firstSet = FirstIP
WScript.Sleep 3
Set objWMIService = GetObject("winmgmts:")
Set SecondIP = objWMIService.ExecQuery("SELECT * FROM " & "Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
Set secondSet = SecondIP
results = StrComp(firstSet, secondSet, 1)
If Not results = True Then
updateURL = "MyURL"
Set req = CreateObject("MSXML2.XMLHTTP.6.0")
req.Open "GET", updateURL, False
req.Send
End If

vbscript Remove mapped drive if the drive letter and path matches

Here is the vbscript that I have which should remove the netwrok drive if it matches the letter and the path but it does not work properly and the array shows 13 mapped drives which I only have 5 on my computer. Doesnt it suppose to check all the available mapped drives on the user's mapped computer?
Set objShell = CreateObject("Wscript.Shell")
Set objNet = WScript.CreateObject("Wscript.Network")
Set objExec = objShell.Exec("net use ")
strMaps = LCase(objExec.StdOut.ReadAll)
MapArray=split(strMaps,CHR(10))
for x=1 to ubound(MapArray)
if instr(MapArray(x),"W:") AND instr(mapArray(x),"\\path\folder$") then
objNet.RemoveNetworkDrive "W:",true,true
end if
if instr(MapArray(x),"U:") AND instr(mapArray(x),"\\path\folder$") then
objNet.RemoveNetworkDrive "U:"
end if
next
To enumerate network drives.
Set NetDrives = WScript.CreateObject("WScript.Network").EnumNetworkDrives
For X = 0 to NetDrives.Count -1 Step 2
MsgBox NetDrives(x) & " " & NetDrives(x+1)
Next
To do what you want. We don't test then do usually. We do and test what happened. Testing most things usually takes up almost the same resources as doing.
On Error Resume Next
Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemoveNetworkDrive "Y:"
Msgbox err.description
Again anything involving files and registry (because users delete) and networks or internet (because by nature are unreliable) should use error handling.

Unlock bitlocker drive with VBScript

I'm trying to script out the unlocking of a bitlocker drive using a DRA certificate. I'm attempting to use the WMI Method UnlockWithCertificateFile and I can't for the life of me figure out what i'm doing wrong or even find an example.
I know the certificate and pin work because i can manually unlock the drive using manage-bde -unlock....
when i run my script i get a return value of -2146885623 wich i've looked up to be -2146885623, "Cannot find the requested object."
i'm not sure what object its talking about.
here is the code i'm using (minus the pin)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\Security\MicrosoftVolumeEncryption")
' Obtain an instance of the the class
' using a key property value.
Set objShare = objWMIService.Get("Win32_EncryptableVolume.DeviceID='\\?\Volume{a2965903-4af0-11e2-be65-806e6f6e6963}\'")
' Obtain an InParameters object specific
' to the method.
Set objInParam = objShare.Methods_("UnlockWithCertificateFile"). _
inParameters.SpawnInstance_()
' Add the input parameters.
objInParam.Properties_.Item("PathWithFileName") = "D:\BitLocker.pfx"
objInParam.Properties_.Item("Pin") = "PinCode
' Execute the method and obtain the return status.
' The OutParameters object in objOutParams
' is created by the provider.
Set objOutParams = objWMIService.ExecMethod("Win32_EncryptableVolume.DeviceID='\\?\Volume{a2965903-4af0-11e2-be65-806e6f6e6963}\'", "UnlockWithCertificateFile", objInParam)
' List OutParams
Wscript.Echo "Out Parameters: "
Wscript.echo "ReturnValue: " & objOutParams.ReturnValue
has anyone ever used this method or can anyone see something i may be doing wrong? also i'm using the windows 8 commandline recovery option, i'm not sure if that makes a difference because i have tested calling other methods and wmi and scripting seem to be fully implemented.

Get username from all users in specific group

I must be missing something here, or I'm blind or I've had too much coffee.
Basically, I'm trying to get the username of each user in a specific group i AD.
Then I want to take these username and pass those to a powershell script. But that's another case. This is probably a quick win for you guys.
Dim groupName
groupName = "LDAP://CN=groupname,OU=MailGroups,OU=Exchange,OU=MainContainer,DC=MyDomain,DC=com"
Set objGroup = GetObject(groupName)
For Each strUser in objGroup.Member
Set objUser = GetObject("LDAP://" & strUser.UserName)
Next
And I get this error message Object required: 'strUser'
Why is this happening? strUser is right there!
If I change the snippet a bit to this:
Set objGroup = GetObject(groupName)
For Each strUser in objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)
msgbox objUser.Name
Next
Then I get the result CN=Doe John in the message box for each member.
try
For Each strUser in objGroup.Members
not Member but Member*s*
This site will tell you more than you ever want to know about AD and VBS:
http://www.computerperformance.co.uk/vbscript/vbscript_group_enumerate_members.htm

Resources