Jump to content
Sign in to follow this  
mbusse

Help with Script

Recommended Posts

Hello All.

I am looking for a little assistance from the experts here. Cyberslug was kind enough to share a snippet with me to assist in a task at hand. It is close to what I need and was wondering if someone can fill the gaps for me. I have been using V2 for quite some time, but it appears it is time to move to V3, I am still a rookie and do not fully understand V3 but am trying so forgive the question if it is a simple one.

What I need to do is via loging script find the persistant drive mappings of a computer, then log the user id and mappings to an excel spreadsheet. A second piece but I feel much harder is finding UNC mapping shortcuts on the desktop.

Here is the snippet that I have.

MsgBox(4096,"Mappings", _GetMappedDriveInfo())

Exit

Func _GetMappedDriveInfo()

Local $i, $letter, $info, $t = ""

For $i = Asc("A") to Asc("Z")

$letter = Chr($i) & ":"

$info = DriveMapGet($letter)

If Not @error Then $t = $t & $letter & " " & $info & @CRLF

Next

Return $t

EndFunc

Other than the help in V3, can anyone point me to other resources to assist with grasping V3. Not that the help is not good, just not detailed enough for a rookie.

All help with this is appreciated and kudos to the author and this community for a wonderful tool..

Thanks, Mark..

Share this post


Link to post
Share on other sites

Hello All.

Here is the snippet that I have.

MsgBox(4096,"Mappings", _GetMappedDriveInfo())
Exit

Func _GetMappedDriveInfo()
   Local $i, $letter, $info, $t = ""
   For $i = Asc("A") to Asc("Z")
      $letter = Chr($i) & ":"
      $info = DriveMapGet($letter)
      If Not @error Then $t  = $t & $letter & "  " & $info & @CRLF
   Next
   Return $t
EndFunc

<{POST_SNAPBACK}>

Wrap your code in [.code][./code] tags (without the .) that makes it eaiser for us to read.

I'm really thinking that $t needs to be an array

Dim $t[27]

Use the [0] array portion to store the # of containers (26) and then use 1 thru 26 to store the drive letters.

Or, don't use the string of spaces....

If Not @error Then $t = $t & $letter & " " & $info & @CRLF

Change it to

If Not @error Then FileWriteLine($file,$t & "," & $letter & "," & $info & @CRLF)

That way, your code becomes:

$file = FileOpen("C:\test.csv",1)
_GetMappedDriveInfo()
FileClose($file)
Run("Excel C:\test.csv")
Exit

Func _GetMappedDriveInfo()
   Local $i, $letter, $info, $t = ""
   For $i = Asc("A") to Asc("Z")
      $letter = Chr($i) & ":"
      $info = DriveMapGet($letter)
      If Not @error Then FileWriteLine($file,$t & "," & $letter & "," & $info & @CRLF)
   Next
   Return $t
EndFunc

CSV is what's called a "string delimited file" usually commas or tabs. Each bit of information separated by the comma becomes its own cell in XL

Edit: Forgot to close the file. Doh!

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

Wrap your code in [.code][./code] tags (without the .) that makes it eaiser for us to read.

I'm really thinking that $t needs to be an array

Dim $t[27]

Use the [0] array portion to store the # of containers (26) and then use 1 thru 26 to store the drive letters. 

Or, don't use the string of spaces....

If Not @error Then $t  = $t & $letter & "    " & $info & @CRLF

Change it to

If Not @error Then FileWriteLine($file,$t & "," & $letter & "," & $info & @CRLF)

That way, your code becomes:

$file = FileOpen("C:\test.csv",1)
_GetMappedDriveInfo()
FileClose($file)
Run("Excel C:\test.csv")
Exit

Func _GetMappedDriveInfo()
   Local $i, $letter, $info, $t = ""
   For $i = Asc("A") to Asc("Z")
      $letter = Chr($i) & ":"
      $info = DriveMapGet($letter)
      If Not @error Then FileWriteLine($file,$t & "," & $letter & "," & $info & @CRLF)
   Next
   Return $t
EndFunc

CSV is what's called a "string delimited file" usually commas or tabs.  Each bit of information separated by the comma becomes its own cell in XL

Edit: Forgot to close the file.  Doh!

<{POST_SNAPBACK}>

Thanks for the reply, I am not sure why but it does not do a CRLF in the csv even though it is in there? Also, are you aware of a way to pull the user id and put it in Cell A? I cannot find anything in the help file..

Share this post


Link to post
Share on other sites

Thanks for the reply, I am not sure why but it does not do a CRLF in the csv even though it is in there? Also, are you aware of a way to pull the user id and put it in Cell A? I cannot find anything in the help file..

<{POST_SNAPBACK}>

Cell A would be the info contained in the first area before the first comma.

In this case, if you'd like to format your cells with a header, you'll have to filewrite that line first before calling the function. Open Excel and make the top line cell header, and save it as a CSV. Then you'll have the pre-formatted line ready for copy/paste into the script.

All depends on how the userID is stored on the computer. Try opening a dos CMD box and type "set" (no quotes)

You could get a userID from the environment variables that Windows sets with EnvGet("variable"), For example: $user = EnvGet("TODAY") would return 20050304 on my system. YMMV.

Try playing around with the LF statment. Try @LF, and @CR since @CRLF seems to not work. I generally have no problems using @LF by itself.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...