Jump to content

Can this be converted VBS to Autoit?


 Share

Recommended Posts

Can someone show me the below converted from VBS to Autoit?

On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")

Set objNetwork = CreateObject("Wscript.Network")

strUserPath = "LDAP://" & objSysInfo.UserName

Set objUser = GetObject(strUserPath)

For Each strGroup in objUser.MemberOf

strGroupPath = "LDAP://" & strGroup

Set objGroup = GetObject(strGroupPath)

strGroupName = objGroup.CN

Select Case strGroupName

Case "APP-Office"

objNetwork.RemoveNetworkDrive "q:"

objNetwork.MapNetworkDrive "q:", "\\umk-s01\data"

Case "APP-Billing"

objNetwork.RemoveNetworkDrive "j:"

objNetwork.MapNetworkDrive "j:", "\\umk-n01\on"

End Select

Next

Link to comment
Share on other sites

$objSysInfo = ObjCreate("ADSystemInfo")
$objNetwork = ObjCreate("Wscript.Network")
$strUserPath = "LDAP://" & $objSysInfo.Username
$objUser = ObjGet($strUserPath)
for $strGroup in $objUser.MemberOf
    $strGroupPath = "LDAP://" & $strGroup
    $objGroup = ObjGet($strGroupPath)
    $strGroupName = $objGroup.CN
    
    Switch $strGroupName
        Case "APP-Office"
            $objNetwork.RemoveNetworkDrive("q:")
            $objNetwork.MapNetworkDrive("q:", "\\umk-s01\data")
        Case "APP-Billing"
            $objNetwork.RemoveNetworkDrive("j:")
            $objNetwork.MapNetworkDrive("j:", "\\umk-n01\on")
    EndSwitch
    
Next

Edited by ame1011
[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]
Link to comment
Share on other sites

$objSysInfo = ObjCreate("ADSystemInfo")
$objNetwork = ObjCreate("Wscript.Network")
$strUserPath = "LDAP:/?" & $objSysInfo.Username
$objUser = ObjGet($strUserPath)
for $strGroup in $objUser.MemberOf
    $strGroupPath = "LDAP://" & $strGroup
    $objGroup = ObjGet($strGroupPath)
    $strGroupName = $objGroup.CN
    
    Switch $strGroupName
        Case "APP-Office"
            $objNetwork.RemoveNetworkDrive("q:")
            $objNetwork.MapNetworkDrive("q:", "\\umk-s01\data")
        Case "APP-Billing"
            $objNetwork.RemoveNetworkDrive("j:")
            $objNetwork.MapNetworkDrive("j:", "\\umk-n01\on")
    EndSwitch
    
Next
Thank You for the reply

I get an Error:

for $strGroup in $objUser.MemberOf

for $strGroup in $objUser ERROR

Variable must be of type "Object".

Link to comment
Share on other sites

$objSysInfo = ObjCreate("ADSystemInfo")
$objNetwork = ObjCreate("Wscript.Network")
$strUserPath = "LDAP://" & $objSysInfo.UserName
$objUser = ObjGet($strUserPath)
    For $strGroup in $objUser.MemberOf()
        $strGroupPath = "LDAP://" & $strGroup
         $objGroup = ObjGet($strGroupPath)
        $strGroupName = $objGroup.CN
        Select 
            Case $strGroupName="App-Office"
                If FileExists("j:") Then 
                    $objNetwork.RemoveNetworkDrive ("j:")
                EndIf
                $objNetwork.MapNetworkDrive ("j:", "\\files\userdata")
            Case $strGroupName="APP-Billing"
                $objNetwork.RemoveNetworkDrive ("h:")
                $objNetwork.MapNetworkDrive ("h:", "\\files\data")
        EndSelect
    Next

I am not getting an error from the mapping anymore.

What other ways are there to determine if the drive exists? Thanks

If FileExists("j:") Then

$objNetwork.RemoveNetworkDrive ("j:")

EndIf

Also I get a Line -1

Error: Variable must be of type "Object". on other workstations

Edited by TheAdmin
Link to comment
Share on other sites

$objSysInfo = ObjCreate("ADSystemInfo")
$objNetwork = ObjCreate("Wscript.Network")
$strUserPath = "LDAP://" & $objSysInfo.UserName
$objUser = ObjGet($strUserPath)
    For $strGroup in $objUser.MemberOf()
        $strGroupPath = "LDAP://" & $strGroup
         $objGroup = ObjGet($strGroupPath)
        $strGroupName = $objGroup.CN
        Select 
            Case $strGroupName="App-Office"
                If FileExists("j:") Then 
                    $objNetwork.RemoveNetworkDrive ("j:")
                EndIf
                $objNetwork.MapNetworkDrive ("j:", "\\files\userdata")
            Case $strGroupName="APP-Billing"
                $objNetwork.RemoveNetworkDrive ("h:")
                $objNetwork.MapNetworkDrive ("h:", "\\files\data")
        EndSelect
    Next

I get a Line -1

Error: Variable must be of type "Object". on other workstations

Edited by TheAdmin
Link to comment
Share on other sites

I don't see any problem with this syntax:

If FileExists("j:") Then

But we do have the function IsObj:

If Not IsObj($squirrely_business) Then

The line checks to see if $squirrely_business is a variable containing an object type.

Das Häschen benutzt Radar

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...