Sign in to follow this  
Followers 0
KSum

@ScriptDir and Network Drives

15 posts in this topic

@ScriptDir is returning a network mapped drive instead of the UNC.  How do I get this to give me the UNC instead?  I though it returned this by default.

Karl

Share this post


Link to post
Share on other sites




My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Have you tried running it using the UNC path instead of a mapped drive path? Or is it required in your case to use the mapped drive?

Share this post


Link to post
Share on other sites

I need the UNC path.  I am getting the mapped drive from @ScriptDir.  So when I use @ScriptDir I get   G:MyFolderPath  and not  ServerShareMyFolderPath. 

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Your solution works fine for me.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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()?

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

It may have shown up as a UNC path before, because you had opened up the .au3 file from network instead of a mapped drive.

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

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

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