Sign in to follow this  
Followers 0
JimC

help with function

2 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  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

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  
Followers 0