Jump to content
Sign in to follow this  
TheAdmin

Can this be converted VBS to Autoit?

Recommended Posts

TheAdmin

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

Share this post


Link to post
Share on other sites
ame1011

$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]

Share this post


Link to post
Share on other sites
TheAdmin

$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".

Share this post


Link to post
Share on other sites
Squirrely1

I see a typo on line 3 - the "?" should be a "/"


Das Häschen benutzt Radar

Share this post


Link to post
Share on other sites
TheAdmin

I see a typo on line 3 - the "?" should be a "/"

Good catch, now it has an error:

$objNetwork.RemoveNetworkDrive("q:") ERROR

Share this post


Link to post
Share on other sites
TheAdmin

$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

Share this post


Link to post
Share on other sites
ame1011

Good catch on the typo, fixed.

I quickly did that in a couple minutes hence the typing mistake.


[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]

Share this post


Link to post
Share on other sites
TheAdmin

$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

Share this post


Link to post
Share on other sites
Squirrely1

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.