Jump to content

Recommended Posts

Posted

i am trying to write a small function to return a user network home drive, but my results are returned as 0. I would like to return the value of the home drive or exit with an error. Thansk in for your assistance.

#NoTrayIcon
;***************************************
;
; Network HOME Drive Tool
;
;***************************************
#include <Process.au3>
; Variables
$numofDrives = ""
$home = ""
$homedrive=gethomedrive($home)
msgbox(1, "Home Drive Results", $homedrive)

Func gethomedrive($home)
$user=@UserName
$allDrives = ""
$allDrives = DriveGetDrive( "network" )
if $allDrives = "" then
msgbox(1,"Home Drive Search Results", "No Network Drives Found !!!                                                                                   Please contact local Technical Support for assistance!!!!")
else
$numofDrives=$allDrives[0]
For $i = 1 to $numofDrives Step 1
  $curDriveLtr = $allDrives[$i]
  $curDrivePath = DriveMapGet($curDriveLtr)
  $result=StringInStr($curDrivePath, $user)
  msgbox(1, "Result", $result)
  If $result > 0 Then
   $home = (@UserName & $curDrivePath & ' '&$curDriveLtr)
   msgbox(1, "HOMEDRIVE", $home)
   Return
  EndIf
Next
EndIf
msgbox(1,"Home Drive Search", "No Home Drive Found !!!                                                                                              Please contact local Technical Support for assistance!!!!")
EndFunc
Exit
Posted (edited)

Here you are:

#NoTrayIcon
;***************************************
;
; Network HOME Drive Tool
;
;***************************************
#include <Process.au3>
$numofDrives = ""
$home = 0
gethomedrive()

msgbox(1, "HOMEDRIVE test", $home)

Func gethomedrive()
$user=@UserName
$allDrives = DriveGetDrive( "network" )
if $allDrives = "" then
_nodrive()
else
$numofDrives=$allDrives[0]
For $i = 1 to $numofDrives Step 1
  $curDriveLtr = $allDrives[$i]
  $curDrivePath = DriveMapGet($curDriveLtr)
  $result=StringInStr($curDrivePath, $user)
  If $result > 0 Then
   $home = @UserName & $curDrivePath & @CRLF& "Drive letter: "& $curDriveLtr&""
   Return $home
  EndIf
Next
EndIf
EndFunc
Exit

Func _nodrive()
    msgbox(1,"Home Drive Search Results", "No Network Drives Found !!! "& @CRLF & "Please contact local Technical Support for assistance!!!!")
EndFunc
Edited by MPH

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
  • Recently Browsing   0 members

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