When I run the code, I get an error saying
ActiveX component can't create object: 'Shell.LocalMachine'
Class MachineName
Private internal_ComputerName
Public Function SetMachineName
Set objComputer = CreateObject("Shell.LocalMachine")
internal_ComputerName = objComputer.MachineName
End Function
Public Property Get GetMachineName
GetMachineName = internal_ComputerName
End Property
End Class
Dim objMachine
Set objMachine = New MachineName
objMachine.SetMachineName
thanks for this. I am having the same problems when using this Shell.Localmachine on my windows 7 64 bit machine when i try to run a simple vbscript code. I had to default to WScript.Network instead:
'just a test script
'set objComputer = CreateObject("Shell.LocalMachine")
'wscript.echo "computer name" & objcomputer.machinename
Set objWshNet = CreateObject("WScript.Network")
wscript.echo "computer name : " & objwshnet.computername
Morbo said "Must admit I hadn't come across that object before. I'd normally create a "WScript.Network" object and get the ComputerName property. If you're diagnosing "Shell.LocalMachine" I can tell you that on my copy of XP it is provided by system32\shgina.dll"
Related
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
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.
I need to check a Windows Server (many of them a day) and just verify that Unused NIC's are disabled. This is just one of many checks I'm doing.
I'm trying to figure out how I can do this and this is my following code.
It gives me an error with objNetwork.PhysicalAdapter saying
Object doesn't support this property or method:
'objNetwork.PhysicalAdapter'
Sub CheckUnusedNICs()
WScript.Echo("Check for unused NICs")
WScript.Echo("------------------------------------")
Set colNetwork = objWMISrvc.ExecQuery("SELECT * from Win32_NetworkAdapter")
For each objNetwork in colNetwork
WScript.Echo objNetwork.AdapterTypeID & vbCrLf
WScript.Echo objNetwork.PhysicalAdapter
'If (objNetwork.AdapterTypeID = 0 AND objNetwork.PhysicalAdapter = True) Then
' WScript.Echo("Placeholder")
' End If
Next
End Sub
I'm by no means proficient in VBScript but I'm learning it as I go.
The WMI Win32_NetworkAdapter class doesn't have a PhysicalAdapter property.
Use NetConnectionStatus and ConfigManagerErrorCode properties instead.
A device would be:
Enabled and connected if:
NetConnectionStatus = 2
Enabled and no cable is plugged in if:
NetConnectionStatus = 7
Disconnected due to disabled device if:
(NetConnectionStatus = 0) and (ConfigManagerErrorCode = 22)
More details about Win32_NetworkAdapter class including the full list of the above codes can be found at:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx
I am having a minor problem automating the starting and stopping of services. When I open services.msc and look at the list of services, they all have names. However, when I run this code:
Dim objService As Object
Dim objSet As Object
IsServiceRunning = False
Set objSet = GetObject("winmgmts:").ExecQuery("SELECT * FROM Win32_Service")
For Each objService In objSet
If (UCase(strServiceName) = UCase(objService.Name)) And (UCase(objService.State) = UCase("Running")) Then
IsServiceRunning = True
End If
Next
The objService.Name value is not the same as the name in the list. For example, "Computer Browser" is just "browser", "Distributed File System" is "dfs", and "Net Logon" is "netlogon". Is there a way to pull the full, longer name for these services from this objService object? I can workaround this, but for the sake of clarity in the code I'd rather use the same value for determining if the service is running, making a NET START or NET STOP command line call, and logging.
Just use objService.Caption to access "long name" of service.
I discovered the name of the property like this:
For Each objService In objSet
For Each vElem In objService.Properties_
Debug.Print vElem.Name; "=";
Debug.Print vElem.Value
Next
Exit For
...
Next
Just put objService in watch window to find out Properties_ property. Put vElem in watch window too to find Name and the default property Value (besides IsArray, etc.) of SWbemProperty object.
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.