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

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

Related

VBScript WMI PnPEntity obtaining HardwareID

I'm looking to extract the hardwareID from each device installed on a system using VBScript.
I can extract most properties from the PnPEntity class however the HardwareId or CompatibleId does seem to cause trouble - I'm presuming because it potentially returns an array.
My script is as follows:
Set TxtDriverOutput = objFSO.CreateTextFile("C:\Program Files\xxx\drivers.log", 8, True)
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
txtDriverOutput.WriteLine Now() & Chr(32) & "Begin HardwareID WMI Query"
txtDriverOutput.WriteLine "----------------------------------------------------------------------------"
txtDriverOutput.WriteLine ""
Set colsHardwareID = objWmiService.ExecQuery("Select * from Win32_PnPEntity")
For Each objItem In colshardwareID
For Each StrHardwareID In objItem.HardwareID
txtdriveroutput.WriteLine StrHardwareID
Next
Next
When I run the script, I see one hardware ID populated into the text file - and then I get Error: Object is not a collection flagged on the line of my second for loop (sometimes I have seen it flag the line after it errors for some reason so maybe take that with a pinch of salt.
I have tried using ObjItem.HarwareID.count, UBound(ObjItem.HardwareID) in case there is a PnP Device that doesn't have a hardware ID (not sure if possible). Can anyone point me in the right direction? Thanks!
I managed to get to the bottom of this in the end.
I had to use the following:
For Each objItem In colshardwareID
If Not IsNull(objItem.HardwareID) Then
For Each StrHardwareID In objItem.HardwareID
ReDim Preserve ArrHardwareID(i)
ArrHardwareID(i) = strHardwareID
i = i + 1
Next
End If
Next
As expected - the collection was empty. A .count or .isempty was not working, it had to be IsNull.

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.

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

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

Verify what website I am currently on

Does anyone know of a quick and easy way to verify what website I'm currently on?
I have made some script that logs me into a website, but if the user is already logged on, it will create an error.
If anyone knows a good way to tell if they are already logged in, please let me know!
The script is as follows:
Username = InputBox("Please input username")
Password = InputBox("Please input password")
Set objShell = WScript.CreateObject("WScript.Shell")
Dim IE
Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
IE.Visible = 1
IE.navigate "http://wsmmart.itg.ti.com/"
Do
WScript.Sleep 250
Loop While IE.ReadyState < 4 And IE.Busy
IE.Document.All.Item("fld2").Value = Username
IE.Document.All.Item("fld5").Value = Password
'IE.Document.All.Item("Submit").Click
The following code will loop through all open IE windows and look to see if any one of them has the term "wsmmart.itg.ti." in the url. If it finds a match it will control that window and proceed to insert your username, pw, etc. If it doesn't find a match then you could run your code to open a new window
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
On Error Resume Next ' sometimes more web pages are counted than are open
my_url = objShell.Windows(x).Document.Location
If my_url Like "*" & "wsmmart.itg.ti." & "*" Then 'find an existing wsmmart web page
Set ie = objShell.Windows(x)
Exit For
Else
if x=(IE_count - 1) then
' do your stuff to open a new window
end if
End If
Next
on error goto 0
now try to insert your username, pw, etc. , put it in an if statement. if you get an error back, then you're already logged in

Classic ASP (VBScript), 2008 R2, error using AD to authenticate

I have moved a web site from Win2003 x32 to Win2008R2 x64. It works fine on the old server. The web site uses active directory to authenticate. I get this error on 2008: -2147023584 : A specified logon session does not exist. It may already have been terminated. I have tried switching to classic mode, etc. with no change. It does execute VBScript code (otherwise I wouldn't get the error).
Here is the code:
Function AuthenticateUser(UserName, Password)
On Error Resume Next
Dim oADsNamespace, oADsObject
Dim strADsNamespace, strADsPath
strADsPath = "WinNT://ibcschools.edu"
strADsNamespace = left(strADsPath, instr(strADsPath, ":"))
Set oADsObject = GetObject(strADsPath)
Set oADsNamespace = GetObject(strADsNamespace)
Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, UserName, Password, 0)
Response.Write(Err.Number & " : " & Err.Description & "<br />")
If Err.Number = 0 Then
Set oADsNamespace = Nothing
Set oADsObject = Nothing
Set strADsNamespace = Nothing
Set strADsPath = Nothing
AuthenticateUser = True
Else
Set oADsNamespace = Nothing
Set oADsObject = Nothing
Set strADsNamespace = Nothing
Set strADsPath = Nothing
AuthenticateUser = False
End If
End Function
Any help would be appreciated. Thanks.
Your problem seems to be related to using WinNT provider with OpenDSObject.
Things you could try:
Replace WinNT with LDAP provider.
Try running your standalone VBS file
under IIS/ApplicationPool user privileges.
Okay, so I got it working. Before it worked without the domain name, but now requires it. I think it has something to do with the app pool logging in on the old server versus this one. I am going to work on it a little more. I don't want to change all the sites.

Resources