Sign in to follow this  
robopp

Getting Desktop Path

Recommended Posts

Is there a way to get the desktop path programatically? The cmd desktop path shortcut - %userprofile%/desktop - doesn't work.

Share this post


Link to post
Share on other sites

Not built in.  I would probably use a trick, probably with a batch file.  The batch file would just have something like:

echo %userprofile%/desktop > c:\data\desktopPath.txt

You'd run it from DAQFactory using shellExecute():

system.shellExecute("cmd.exe","c:\data\myBatchFile.bat")

Then you can simply use the file. functions to read the desktopPath.txt file and get the results.

This is off the cuff, but should work, possibly with minor tweaks.  Test each part.

Share this post


Link to post
Share on other sites
On 5/8/2020 at 4:04 PM, AzeoTech said:

Not built in.  I would probably use a trick, probably with a batch file.  The batch file would just have something like:

echo %userprofile%/desktop > c:\data\desktopPath.txt

You'd run it from DAQFactory using shellExecute():

system.shellExecute("cmd.exe","c:\data\myBatchFile.bat")

Then you can simply use the file. functions to read the desktopPath.txt file and get the results.

This is off the cuff, but should work, possibly with minor tweaks.  Test each part.

Hi, I'm also trying to run a batch file, and "system.shellExecute("cmd.exe","c:\data\myBatchFile.bat")" doesn't do anything. 

function LoadAutosamplerFile(string que_file)
   //try
      private string script_dir = "C:\Peak489Win10\LoadCtrlFile.bat"
      private handle = file.Open(script_dir, 0, 1, 0, 1)
      File.Write(handle, "cd C:\Peak489Win10")
      File.Write(handle, "Peak489Win10 -a" + que_file)
      File.Close(handle)
      system.ShellExecute("cmd.exe","C:\Peak489Win10\LoadCtrlFile.bat")
      ?"Batch file (allegedly) executed"
      return 1

Share this post


Link to post
Share on other sites

Figured it out, the command to launch a batch file with shellExecute is 

system.ShellExecute("cmd.exe", "open", "/C C:\data\myBatchFile.bat") 

At least thats the way I got it to work, hope this helps if anyone is looking for how to do that. 

Share this post


Link to post
Share on other sites

Yes, that would be the way.  You can't just pass a batch file to CMD.exe, but instead have to use a flag to tell it to run the particular file.  You can use /C or /K depending on whether you want the window to stay open.

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