Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


I need two codes working together

I need two codes working together

I need two codes working together

I need two different codes working together

the first one is a VBS script:

Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.CreateTextFile("User.bat", False) ' False for ANSI, True for Unicode
Set shell = CreateObject( "WScript.Shell" )
username = shell.ExpandEnvironmentStrings( "%USERNAME%" )
file.WriteLine username

This will get the username and export it to a batch file, or a text file if the extension get changed to .txt

The second code is a batch file used to alter some attributes and permissions

setlocal enableextensions
cd /d "%~dp0"
@echo off
If EXIST "(The user name)" goto UNLOCK
if EXIST "User" goto LOCK
echo s| cacls "(The user name)" /G %USERNAME%:F
attrib -H -S -R "(The user name)"
ren "(The user name)" "User"
goto END
ren "User" "(The user name)"
attrib +H +S +R "(The user name)"
echo s| cacls "(The user name)" /D %USERNAME%
goto END

I need that the VBS script executes this Batch file with the “Username” it got in the first place.
This will be part of a security useful application that I'm trying to put together.
All help will be very appreciated.

RE: I need two codes working together

Hi Lisa,
If you get the USERNAME in your VBscript then you can pass it as command line argument to the batch script.
The batch script could be executed from Vbscript using the WScript.Shell command Run. Here is a little example:

I have this VBscript


wscript.echo "running VBscript: user.vbs"
set fso = CreateObject("Scripting.FileSystemObject")
set shell = CreateObject( "WScript.Shell" )
my_usr_name = shell.ExpandEnvironmentStrings( "%USERNAME%" )
' get environment variable
wscript.echo "username from system environment = '" & my_usr_name & "'"
' create batch command
my_cmd = "user.bat" & " " & my_usr_name
wscript.echo "now executong command : '" & my_cmd & "'"
' run the command
set shell = nothing
wscript.echo "end of VBScript: user.vbs" 

and this batch file


@echo off
echo * running batch script: user.bat
if  %1x==x  goto ARG_NOT_AVAIL
set usr=%1
echo   processing user '%usr%'
echo   ...
goto END

echo Error: Username not passed as command line argument !

echo * end of batch script: user.bat

now when I open the command line window and run this command


cscript /NoLogo user.vbs 

then VBscript runs producing the output


running VBscript: user.vbs
username from system environment = 'MIKROM'
now executong command : 'user.bat MIKROM'
end of VBScript: user.vbs 

additionally other command line window opens where bat file runs


* running batch script: user.bat
  processing user 'MIKROM'
* end of batch script: user.bat
Press any key to continue . . . 

RE: I need two codes working together

Hi Mikrom
Thank you very much for your reply. I cannot give you many details about this application I'm trying to put together because in the end it will be a commercial software. A super Vault with a very strong encryption. This VBS file, together with the batch file will be a small part of the application. It is intended to be applied in a common folder that will work like if it was the main user folder. This will be used to hide an important part of the program. And that is the reason that it must have the username on it. Having said this and because the attributes and permissions that the batch file must apply to that common folder, the process must run in total silent mode. Now, and because the batch file must have a folder name to apply its function to that folder. It needs to get the name from the VBS file, all in the right places, so it can be executed by the VBS file properly.

RE: I need two codes working together

>I need that the VBS script executes this Batch file with the “Username” it got in the first place

you could always rewrite the batch file as VBScript ...

RE: I need two codes working together


VBS script executes this Batch file with the “Username” it got
IMO this is what I posted above: the VBscript user.vbs executes the batch file user.bat with username I got in VBscript from system environment. Then the batch file can do something with the username.

RE: I need two codes working together

Hi Mikrom
Well, I couldn't figure it out. Is there any other language with which one could make an executable file to apply this required definitions in silent mode. I mean like an ON/OFF system. Please help me with this and I'll include your name in my program's credits ... Now for you to understand better what I need, just create a common folder in your desktop like “New Folder” etc. and then rename it with the name you want for example “user” and this special property, like this:
“User.{59031a47-3f72-44a7-89c5-5595fe6b30ee}” Unbelievable isn't it? After this, if you rename or modify one single letter after the (dot) it will become a common folder again, in addition to this I use the attrib command to make it a read only system folder and the cacls command to modify the ACL's in a way that if you apply it to a common folder you will lose all access to it, but in this case and because it will be a Windows special folder, you will be able to open it, but you won't be able to rename it nor delete it, copy it or anything else. Having performed this test you will understand what I really need to be done and that is a ON/OFF switch to this system no matter what language you will use to write it.

RE: I need two codes working together

>Unbelievable isn't it?

Not to everyone! The reason this works is because of the way the shell (i.e your desktop) interprets certain GUIDS, some of which have a special meaning to it - the one you have selected happens to represent the User folder, but there are others, eg A8CDFF1C-4878-43be-B5FD-F8091C1C60D0 - Documents

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close