Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Check Admin - VBS - Win7  (Read 4293 times)

0 Members and 1 Guest are viewing this topic.

nothlit

    Topic Starter


    Intermediate

    Thanked: 2
    Check Admin - VBS - Win7
    « on: September 15, 2010, 10:26:34 AM »
    Would anyone know how to make this work on Windows 7? Running the Script with admin rights doesn't work at least not in my testing. Start CMD in admin mode and then ran the vbs file from that CMD windows and it returns not admin. I'm half thinking it has something to do with this line ...
    Code: [Select]
    Set objComputer = GetObject("WinNT://" & strComputer & "") But I have no idea how to fix it to work with Windows 7. It does work on XP.

    Code: [Select]
    On Error Resume Next
    strTestUser = "TestUser"
    strComputer = "."
    Set objComputer = GetObject("WinNT://" & strComputer & "")
    'Try to create test account
    Set objUser = objComputer.Create("user", strTestUser)
    objUser.SetPassword "blahblah"
    objUser.SetInfo
    'WScript.Echo Err.Number
    If Err.Number <> 0 Then
     WScript.Echo "Not an admin"
    Else
     WScript.Echo "Is an admin"
     'Cleanup test account
     objComputer.Delete "user", strTestUser
    End If

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Check Admin - VBS - Win7
    « Reply #1 on: September 15, 2010, 11:05:20 AM »
    If you are using a 64-bit version of windows you cannot use CreateObject() or GetObject() to create or acquire instances of COM objects.

    I had a very similar problem.

    My solution was to use the 32-bit version of wscript or cscript, found in %systemroot%\syswow64\


    I was trying to dereference Null Pointers before it was cool.

    nothlit

      Topic Starter


      Intermediate

      Thanked: 2
      Re: Check Admin - VBS - Win7
      « Reply #2 on: September 15, 2010, 01:02:50 PM »
      :) :D Awesome ...

      ~bows down to your greatness~ Thanks for the help.