Sign in to follow this  
Followers 0
triodz

Trying to extract info from Command Prompt to use in variable

5 posts in this topic

I am using this in a bigger script, but once I get it working on this smaller scale, I should be good with the bigger one.

Code I am using:

Run(@ComSpec & " /c c: && cd %userprofile% && echo %userprofile% > c:\NAME.txt","",@SW_HIDE)
$name1 = fileopen("c:\NAME.txt",0)
FileReadLine($name1,1)
$data = FileReadLine($name1,1)
DirCreate($data&"\TEST")

Basically:

Use CMD to get username path

Write that path to a TXT file

Read the path

Use this info as a variable ($data)

If I add a msgbox, it reads it out just fine, but the folder is not created. No errors occur and exit code is zero.

As always, any help is welcomed! :)

Share this post


Link to post
Share on other sites



If you're trying to get the path to the user's folder just use the macro for it, @UserProfileDir.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Well, there you go! Thanks so much! Did not know that existed. This is going to help me out alot.

Share this post


Link to post
Share on other sites

@triodz

Just so you know, I dont think you can run BAT commands the way you were trying. You would need to write the commands to a .bat file and then execute that file using Run. Pretty much anything you can't type into the command window (if it were open) wont work in the Run command.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks Beege,

I have figured it out now. I had issues including @UserProfileDir into the runwait command, but figured it all out. Runs like I need it to and I have a couple of happy users and a slightly impressed boss.

My work here is done... :)

Edited by triodz

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  
Followers 0