hey everyone im a bit of a noob with programing because im only 16 so can you please explain your reply simply.

im trying to make a batch file that asks for a password and opens a file and if the password is wrong displays a message i know how to do this with a .vbs file (like the one you type in notepad not like visual basic 6). i will put the .vbs code up and could some one please show me how to put into cmd lanugage

x = inputbox ("type in password")

if x = "mypassword" then
set x = createobject("wscript.shell")
x.run "file i want to open"

else

z = msgbox("wrong",0,"Error")

end if

Dani AI

Generated

Briefly: the problem is how the Windows built-in START command handles quoted text. If the first thing you give START is quoted, Windows treats that quoted string as the window title — not the thing to open. That makes it look like the variable never expanded. The simplest fix is to supply an explicit (even empty) title, then the quoted path:

start "" "%USERPROFILE%\Desktop\Folder"
start "" "%USERPROFILE%\Desktop\My File.txt"

That opens folders and files with their associated program. Use the same pattern whenever a path contains spaces or an environment variable.

To troubleshoot, print the expanded value first so you can see what the batch actually sees:

echo "%USERPROFILE%\Desktop\Folder"

If the echo shows the correct full path, START was the issue; if not, check for typos in the variable name. Also keep in mind that variable expansion in batch files happens at parse time — if you modify variables inside loops or delayed sections you may need delayed expansion (using !var!) — but for a straight password check and open, normal %USERPROFILE% expansion is fine.

Security and UX notes: as discovered, VBScript or PowerShell give nicer input dialogs and can mask input. ’s batch approach works for simple tasks, but storing or comparing plain-text passwords in .bat files is insecure. If you later move to a small app, ’s suggestion to use Environment.GetFolderPath in VB.NET avoids path guessing and is safer. For anything beyond a toy script, use PowerShell or a compiled app and never hard-code real credentials in plain text.

Recommended Answers

All 5 Replies

use this in batch file

@echo off
set /p pass= What is Password?

if %pass% ==yourpassword start c:\passwordprotected.txt

thanks you are my hero :)

small problem im trying to use the %userprofile% command for the file location ( %userprofile%\Desktop\Folder) but it wont open the full location it just opens the %userprofile% part what am I doing wrong???

Check out this thread about "UserProfile".

You can also use this to get a user's Desktop directory.

Dim sCoolDesktopDirectory As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
        MsgBox(sCoolDesktopDirectory)

%USERPROFILE%\Desktop\myfile.txt

this works fine to open a file but to open a folder use

explorer.exe %USERPROFILE%\Desktop\Folder

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.