06-03-2010 11:58 AM
Hi,
I've written a utility (in LabView) to map one of several network drives based on the user's input to the local host computer. The utility requires that the user enter the username and password for the drive they are trying to access.
I am using the System Exec vi to call a batch file (with parameters based on the user's selection) to map the requested drive. (The batch file uses the usual "NET USE" for drive selection and password prompting. Also, I'm using the /P to prompt for the user name).
Everything works pretty well except:
If I set the "Wait for Completion" on the System Exec vi to "True", the DOS command window opens and shuts very quickly, not allowing the user to enter the username and password, so the drive doesn't get mapped. When the window closes, the System Exec vi proceeds b/c it thinks the batch file has completed but the rest of the code errors out b/c it's referencing a mapped drive that doesn't exist.
If I set the "Wait for Completion" to "False", the batch file runs, the command window opens with the prompt for the user name. After the user name is entered, NET USE prompts for the password. Once the Password is entered, the batch file goes about mapping the drive, which takes a few seconds. (All this is as it should be).
Unfortunately, b/c the "Wait for completion" is set to "False", the System Exec vi has finished executing (understandably) before I can even enter the username in the command window and my subsequent code is (again) running with a reference to a mapped drive that doesn't exist.
I'm prefacing my batch file call with "cmd /x /c" in the command line of the system exec vi (and appending with the necessary parameters). Once the drive is mapped (either by running the code a second time or by manually mapping it), the code works fine (which verifies that the proper drive is getting mapped, etc.)
Anyway, is there a way I can get the System Exec vi to wait until the drive is mapped before finishing?
06-04-2010 02:48 PM
Hi JTT844,
Off the top of my head, it seems that there are a couple workarounds that may not be the ideal situation, but should be easy to implement.
1.) Add a wait after the System Exec VI, to allow the mapping to complete.
2.) Add a loop after the System Exec VI that will continue to loop until the user clicks a button on the front panel to indicate that mapping has completed.
Again, I understand that these are not ideal workarounds, but they should get you started at least until a better workaround can be discovered.
Aaron P
National Instruments
Applications Engineer
06-04-2010 03:01 PM
Thanks, Aaron,
I ended up doing something similar to your suggestions; After the drive is mapped, I use the "List Folders" primitive to display the folders on that mapped drive. If the drive isn't mapped, the List Folders.vi outputs error 7 so I run this vi in a loop until the error clears. Once the error is "0, no error", the loop stops and proceeds to the rest of the code.
jt
06-04-2010 03:03 PM - edited 06-04-2010 03:03 PM
I would suggest a polling loop (with a suitable wait) that queries the Volume Info for the drive you are mapping. Until it is mapped, the Volume Info VI should throw an error, when it no longer does, move on with the rest of your code. If the VI still throws an error after a certain timeout, then you can error out the rest of your code.
Still thinking there might be a better way, I just do not have a network drive here to test.
Edit:Not so original of a suggestion.
06-05-2010 02:10 AM
How about as part of the distribution get the user to set a username and password in a set-up stage. This could then either be setup as default or put into a config/ini file? Then you dont need to ask as you can put it in yourself?