0

I am trying to write a simple Batch File to launch an exe using some basic CMD PRMPT functions. I know exactly what I need to do, but my only problem is I don't know how to detect the Desktop Folder? What if its in Documents and Settings, or if they have a newer computer in Users? Ty for any help :)

3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by MasterGberry
Featured Replies
  • USERPROFILE environment variable works for me with Windows 7 [code] #include <iostream> using std::cout; using std::cin; int main() { char* p = getenv("USERPROFILE"); if( p ) cout << p << '\n'; else cout << "USERPROFILE not found\n"; cin.get(); } [/code] Read More

  • I'm not sure you've posted in the correct forum, I think you want the shell scripting forum! Anyway, I think what you're after is this: [CODE] %USERPROFILE%\Desktop [/CODE] So if you wanted to navigate into the current users Desktop folder in your .bat file, then you would use: [CODE] cd … Read More

1

USERPROFILE environment variable works for me with Windows 7

#include <iostream>
using std::cout;
using std::cin;

int main()
{
    char* p = getenv("USERPROFILE");
    if( p )
        cout << p << '\n';
    else
        cout << "USERPROFILE not found\n";
    cin.get();
}

Edited by Ancient Dragon: n/a

Comments
Perfect C++ Example :)
2

I'm not sure you've posted in the correct forum, I think you want the shell scripting forum!

Anyway, I think what you're after is this:

%USERPROFILE%\Desktop

So if you wanted to navigate into the current users Desktop folder in your .bat file, then you would use:

cd %USERPROFILE%\Desktop

Likewise, if you want to pass the path to the Desktop folder as a parameter to the executable you're calling, then in your batch file you could use:

program.exe %USERPROFILE%\Desktop

Or if the program you're calling requires a switch to be specified before the path, then you'll need to do something like this:

program.exe -X %USERPROFILE%\Desktop

where -X is whatever switch you might need to specify before passing the path.

Comments
Perfect explanation :)
So I used the correct environment variable afterall :)
0

Ty both for your answers :) Going to use Jason's since it is a batch file, but I will keep yours in mind for future needing AD :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.