Permission denied: 'GetObject' in Windows 7

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 13 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
goldyfarbs
Posts: 239
Last visit: Thu Mar 07, 2013 8:15 am

Permission denied: 'GetObject' in Windows 7

Post by goldyfarbs »

Someone, please help me out here.. I think I have a serious brainfreeze...I am starting to use Windows 7 much more often now, and I haven't totally switched over to PowerShell Yet, (I know, I need to), but for some reason, I have UAC turned all the way down and my scripts keep dying out on Windows 7 with no remote access...What am I missing here? If I run the script on my local computer it works fine, but the second I try to parse into remote servers it freaks...am I missing something?
User avatar
goldyfarbs
Posts: 239
Last visit: Thu Mar 07, 2013 8:15 am

Permission denied: 'GetObject' in Windows 7

Post by goldyfarbs »

Hey Jeff,

Long time no speak.. No, Simple VBscript on windows 7...

Code: Select all

'Setting Constants

Const FORCESHUTDOWN = 12
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const Overwrite = True
Const Create = True'Dim variables to memory
Dim Wshshell, ObjEnv, FSO, StrTempDir, StrWinDir, StrSysDrv, ServerList, StrComputer
Dim LogFile, Shutdownerror, ShutdownHex, shutdowndescription, address
Dim Shutdownmessage, msg, strSystem32, sComputer,oReg'Setting Variables
Set Wshshell = CreateObject("Wscript.Shell")
Set ObjEnv = WshShell.Environment("Process")
Set FSO = CreateObject("Scripting.FileSystemObject")
StrTempDir = objEnv("TEMP")
StrWinDir = objEnv("WINDIR")
StrSysDrv = objEnv("SystemDrive")
strSystem32 = StrWinDir & "system32"

Call Main()

Function Main()
'Create LogFile
Set LogFile = FSO.OpenTextFile(StrSysDrv & "LogFile.txt",ForAppending,Create)

'Input box to enter Server Name
ServerList = InputBox("Enter File Path here and File Name","Server Check File")
    If ServerList  "" Then
        If FSO.FileExists(ServerList) Then 
            'Read Input File and turn lines into Variables
            Set File = FSO.OpenTextFile(ServerList)
            'Loop through Text File
            Do While File.AtEndOfStream  True
                StrComputer = Trim(File.ReadLine())
            ' Call Shutdown Function 
             ServerInfo( StrComputer )    
             If Ping() = True Then
             WScript.Echo "Ping Status: Pingable"
             End If
             If Ping() = False Then
             WScript.Echo "Ping Status: NOT PINGABLE"
             End If
            Loop 
        Else 
        MsgBox "ERROR!! The File that was selected cannot be located.  Please check the File location", vbCritical, "ERROR!"
        'Exiting Script with Error
        WScript.Quit
        End If     
    Else
        MsgBox "ERROR!! No Input File.  Please Input a Server List to Shutdown.", vbCritical, "File Input Error"
        'Exiting Script with Error
        WScript.Quit
    End If
    
    
'Close logFile
Logfile.Close

'Quit Script
WScript.Quit

End FunctionFunction ServerInfo( sComputer )
WScript.Echo String(Len(sComputer),"*")
WScript.Echo "System Identification: "
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}" & sComputer & "rootcimv2")
Set cComputerData = oWMI.ExecQuery("SELECT * FROM Win32_ComputerSystem")
For Each oItem In cComputerData
    WScript.Echo "Computer Name: " & oItem.Name 
    WScript.Echo "Computer Manufacturer: " & oItem.Manufacturer
    WScript.Echo "Computer Model: " & oItem.Model
Next

Set cComputerData = oWMI.ExecQuery("SELECT * FROM Win32_SystemEnclosure")
For Each oItem In cComputerData
    WScript.Echo "Serial Number: " & oItem.SerialNumber
Next' 
' Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!" & sComputer & "rootdefault:StdRegProv")
' 
'   strkeypath = "HardwareDescriptionSystemCentralProcessor"
'   strValuename = "ProcessorNameString"
'   cpuname = StringRegistry(strkeypath,strValuename)
'   WScript.Echo "CPU Name: " & cpuname
' Set cComputerData = oWMI.ExecQuery("SELECT * FROM Win32_ComputerSystem")
' For Each oItem In cComputerData
'     ProcessorNumber = oItem.NumberofProcessors
' Next
' WScript.Echo "Number of Processors: " & ProcessorNumber
' 
' Set cComputerData = oWMI.ExecQuery("SELECT * FROM Win32_BIOS")
' For Each oItem In cComputerData
'     dtmBIOSDate = oItem.ReleaseDate
'     strBIOSDate = WMIDateStringToDate(dtmBIOSDate)
'     WScript.Echo "BIOS Version Date: " & strBIOSDate
'     WScript.Echo "BIOS Version Number: " & oItem.SMBIOSBIOSVersion
'     
' Next
' 
' Set cComputerData = oWMI.ExecQuery("SELECT * FROM Win32_ComputerSystem")
' For Each oItem In cComputerData
'     WScript.Echo "Total Physical Memory: " & Round(oItem.TotalPhysicalMemory / 1048576,1) & " MB"
' NextEnd Function 

Function StringRegistry(strkeypath,strValuename)
strvalue = " "
oReg.GetStringValue HKEY_LOCAL_MACHINE,strkeypath,strValuename,strValue
StringRegistry = strValue
End FunctionFunction LogFunction( msg )
'Writing to LogFile          
           LogFile.Writeline String(Len("ServerName: " & StrComputer), "*") & VbCrLf & "ServerName: " & StrComputer & VbCrLf & msg
         
End Function 

Function WMIDateStringToDate(dtmBIOSDate)
        WMIDateStringToDate = CDate(Mid(dtmBIOSDate, 5, 2) & "/" & _
     Mid(dtmBIOSDate, 7, 2) & "/" & Left(dtmBIOSDate, 4))
End Function

Function PrintHeadings(heading)
WScript.Echo ""
WScript.Echo heading
WScript.Echo String(len(heading),"-")
'WScript.Echo String(15,"-")
End Function

Function Ping()

    dim objPing, objRetStatus

    set objPing = GetObject("winmgm
	ts:{impersonationLevel=impersonate}").ExecQuery _
      ("select * from Win32_PingStatus where address = '" & StrComputer & "'")

    for each objRetStatus in objPing
        if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode0 Then
           Ping = False
           'WScript.Echo sComputer & " Cannot Ping."
        Else
           Ping = True
           'address = objRetStatus.protocoladdress
           'WScript.Echo sComputer & " Can ping"
        end If
    Next
End Function
Script runs fine from Windows XP..
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Permission denied: 'GetObject' in Windows 7

Post by jhicks »

Sorry. I didn't pay attention to the forum. What errors are you getting and where?
User avatar
goldyfarbs
Posts: 239
Last visit: Thu Mar 07, 2013 8:15 am

Permission denied: 'GetObject' in Windows 7

Post by goldyfarbs »

^^First thing I did... It's when I query Remote machines with Getobject on Windows 7, it dies...
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Permission denied: 'GetObject' in Windows 7

Post by jhicks »

If WBEMTest fails then the problem is not something in VBScipt. In WBEMTest, do you get an error connecting or when running the query? What error do you get? Are you using alternate credentials? Are computers all in the same domain? Could a firewall setting be blocking remote access?
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Permission denied: 'GetObject' in Windows 7

Post by jhicks »

The problem may be your laptop's computer account in AD. Are clocks in synch? Does NETDOM show a secure channel?
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Permission denied: 'GetObject' in Windows 7

Post by rasimmer »

Windows or 3rd party firewall?
User avatar
goldyfarbs
Posts: 239
Last visit: Thu Mar 07, 2013 8:15 am

Permission denied: 'GetObject' in Windows 7

Post by goldyfarbs »

Yup.. Something with my laptop.. I might just rebuild, but would love to not to.. I was blaming win 7, but it appears to be me :-)
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

Permission denied: 'GetObject' in Windows 7

Post by jhicks »

I'll have to remember this.
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

Permission denied: 'GetObject' in Windows 7

Post by rasimmer »

I guess the question is HOW did the DCOM permissions get turned off, which I'm sure it's not by default turned off.
This topic is 13 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked