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 :)

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 5 Years Ago by Ancient Dragon: n/a

Comments
Perfect C++ Example :)

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 :)

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.