Jump to content

@ScriptDir and Network Drives


Recommended Posts

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Is there a way to have it return the UNC instead of the mapped path?  I thought it was supposed to return the UNC based on other forum threads.

I could also use the first array item from  :

$MyPath = _WinNet_GetUniversalName(@ScriptDir)

but I believe I would first have to make sure @ScriptDir is not reporting a UNC

Link to comment
Share on other sites

Can you give an example what DriveMapget returns and what you expect?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Can you give an example what DriveMapget returns and what you expect?

 

I have to deconstruct @ScriptDir if I use DriveMapGet.  If I use:

MsgBox(0,"test" ,DriveMapGet(@ScriptDir))

I get a message box with no message, suggesting that the function fails with a full path.

I would have to split @scriptDir, then get the ServerShare of the drive and then reconstruct it to use RunAs to run something via a UNC  So to display the UNC in a message box for a test, I end up with:

_PathSplit( @ScriptDir, $MyDrive, $MyDir, $MyFile, $MyExtension)
MsgBox(0,"test" ,DriveMapGet($MyDrive) & @CRLF & $MyDir & @CRLF & $MyFile & @CRLF & $MyExtension) ;display the Server\Share and other pieces
MsgBox(0,"test" , DriveMapGet($MyDrive) & $MyDir) ;dispaly the full UNC path

As you can see, to use the full UNC path, I  need to put the strings together again, as shown.  So why not use:

$MyPath = _WinNet_GetUniversalName(@ScriptDir)
_ArrayDisplay($MyPath, "Demo _PathSplit()") ;display all the values
MsgBox(0,"test",$MyPath[0]) :display the full UNC path

And then I can just reference $MyPath[0] when I need the full UNC path.

Either way, I have to know that I am getting the mapped version of @ScriptDir and not the UNC version. or at least act according to which I am getting.

I am still confused as to when @scriptDir returns a UNC and when it returns a UNC.  I am hoping there is a way to force it to return a UNC and be done with it all without any conversions.

Link to comment
Share on other sites

This should give you the UNC path:

$sDir = @ScriptDir
$aDir = StringSplit($sDir, ":")
If @error = 0 Then
    $sInfo = DriveMapGet($aDir[1] & ":")
    $sInfo &= $aDir[2]
    MsgBox(0, "", $sInfo)
EndIf

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Your solution works fine for me.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I came up with something similar, but was of the understanding @ScriptDir was supposed to return a UNC.  Is this not the case?  Is there a setting that can be made to force it to a UNC?

I came up with this which tests for a mapped drive or UNC first as I am almost positive I have seen @ScriptDir give me a UNC before:

#include <WinNet.au3>

$ScriptPath = @ScriptDir
;Make sure it is a UNC and not a mapped drive
if StringInStr($ScriptPath, ":") > 0 Then
    $MyPath = _WinNet_GetUniversalName(@ScriptDir)
    $ScriptPath = $MyPath[0]
EndIf

Is there a reason I should not use _WinNet_GetUniversalName()?

Link to comment
Share on other sites

There are many ways to skin a cat. Use whichever solution returns the correct result.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Correct. I just opened a script in SciTe and passed the UNC path to the open dialog. Then @ScriptDir gives you the UNC path.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I went through some trouble like this before while trying to make a login script that checks if it is running from the network and if so copy itself to the users' appdata and run again.

But eventually I had an environment that had appdata stored on the server. :x 

This is how I learned to just do it with:

If @ScriptDir <> @AppDataDir Then _CopyandRun

Which of course was simpler, more reliable, and faster.

Edited by blckpythn
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...