Jump to content

Some help required for a Batch file....


Recommended Posts

Hello,

I'm trying to make a batch file that will allow me to fill in a field with a user name for a roaming profile ownership command. Having to retype this command over and over again is tedious. So I created the following code below; but I'm clueless as to how to change this one field within the command in this batch file for each user. I have some past expereince with C++ and COBOL so I understand programming logic but batch coding is just a matter of understanding the commands.

here is the command: psexec -s "icacls" "d:\profiles\username.DOMAIN.V2" /grant administrators:F /t

the name is bold is the field i'd like to change on each execution of this batch program so I can breeze thru all 550 of these roaming profile recreations since we have a corrupt print driver that f***ed all of the profiles on 6 TS servers including the roaming profile which is now corrupt on all of them. Takes about 25 minutes per user and 550 users ya do the math, lol!!!!
here is my code so far, any help would be appreciated.

@echo offcolor 0Atitle Corrupt Roaming Profile Change.:startecho Welcome, %USERNAME%echo What would you like to do?echo.echo 1. Click here for a Nude photo!echo 2. Take Ownership of User's Roaming Profileecho. echo 0. Quitecho.set /p choice="Enter your choice: "if "%choice%"=="1" goto pervertif "%choice%"=="2" goto ownership-changeecho.if "%choice%"=="0" exitecho Invalid choice: %choice%echo.pauseclsgoto start:pervertclsecho your a pervert, you know it, you clicked on this option shame on you!!!echo.goto cancel-special:ownership-changeecho.echo.psexec -s "icacls" "d:\profiles\username.DOMAIN.V2" /grant administrators:F /t echo roaming profile forced ownership change in progress...echo.:cancel-specialset /p cancel="Type cancel to stop action: "if not "%cancel%"=="cancel" exitclsecho Action is cancelled.echo.pauseexit



----------------------------

this is what I'm trying to do. Basically the command below is used to force ownership of the roaming profile since it's corrupt. What I'm hoping is possible is to make a input field that allows me to change the last part of the field below "username.domain.v2" on each execution of the batch file so I can breeze thru the recreations.

:ownership-changeecho.echo.psexec -s "icacls" "d:\profiles\username.DOMAIN.V2" /grant administrators:F /techo roaming profile forced ownership change in progress...echo.


I'm trying to figure out a way to do like a command like this, just don't know the command

if ."d:\profile\" == "d:\profile\" input field is require for last clause

I just don't know how to script it into the code to input it into the batch field above...

Any help would be appreciated, it's just this part i'm unsure how to code, everything else works fine....

Edited by Yzöwl
bold text converted to code box
Link to comment
Share on other sites


There is some communication problems :w00t: you were very detailed in exposing the problem :), but I am completely failing to understand what you mean by "input field" :blushing: , or more precisely how do you plan to "fill" this "input field".

I mean, if I get this right, you could go for a recursive command *similar* to:

@ECHO OFFFOR /F "tokens=* delims=" %%A IN ('DIR /B /AD d:\profiles\ ^| FIND /I "DOMAIN"' ) DO (ECHO psexec -s "icacls" "%%A" /grant administrators:F /t )

That should ECHO the command for each %%A which is a directory under d:\profiles\ and contains "DOMAIN" or "domain".

Is this (once verified you will need to remove the ECHO) what you want to achieve? :unsure:

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

Sorry I see my wording was a bit lax's :-P

basically this command:

psexec -s "icacls" "d:\profiles\username.DOMAIN.V2" /grant administrators:F /t

is inputted each time into command prompt; what I'm seeking to do is to change this field at the end of "d:\profiles\" to allow me to do something like this in a input field in the batch program ie like this:

Please input username folder : jsmith.DOMAIN.V2 then I'd press return and the code above would execute with the command looking like this.....

psexec -s "icacls" "d:\profiles\jsmith.DOMAIN.V2" /grant administrators:F /t

does this make sense and is this due-able?

I'm thinking like a replace command would work, just not sure how to input it....

something like replace "username.domain.v2" with input line then execute psexec -s "icacls" "d:\profiles\username.DOMAIN.V2" /grant administrators:F /t where "username.domain.v2" changes and equals input field....

Edited by deathmage
Link to comment
Share on other sites

Sure, but what I don't understand is if you want to

1) actually TYPE each single jsmith.DOMAIN.V2, jdoe.DOMAIN.V2, etc.,

or if you want to haveprocessed

2) ALL profiles that::

  • are in d:\profiles\
  • have suffix ."DOMAIN.V2"

(I suggested you a possible solution for #2 above)

Or you want something *like*:

@ECHO OFFset /p profile="Enter user profile: "IF EXIST "d:\profiles\%profile%.DOMAIN.V2" ECHO psexec -s "icacls" "d:\profiles\%profile%.DOMAIN.V2" /grant administrators:F /t

jaclaz

Link to comment
Share on other sites

Sure, but what I don't understand is if you want to

1) actually TYPE each single jsmith.DOMAIN.V2, jdoe.DOMAIN.V2, etc.,

or if you want to haveprocessed

2) ALL profiles that::

  • are in d:\profiles\
  • have suffix ."DOMAIN.V2"

(I suggested you a possible solution for #2 above)

Or you want something *like*:

@ECHO OFFset /p profile="Enter user profile: "IF EXIST "d:\profiles\%profile%.DOMAIN.V2" ECHO psexec -s "icacls" "d:\profiles\%profile%.DOMAIN.V2" /grant administrators:F /t

jaclaz

you are awesome; that is exactly what I was looking for!

BTW - do you have a Batch command bible of sorts you know of. I'd like to make a few batch command for automation and it would be sooooo much easier for me. I'm so willing to learn!

now going to see if this works, but now I have a format to work with here. :yes:

now my question, is how do I execute the modified field?

Edited by deathmage
Link to comment
Share on other sites

Here is a VBS solution to what you wanted, a way to get user input and apply that to your command. I also added a section to where you can cancel all the action, before applying the command. I only took a guess at how the command should be in VBS

NOTES

Chr(34) = "

This Chr(34) & "icacls" & Chr(34) = ""icacls"" so it quoted around the areas that need them

Save As UserNameToAdmin.vbs

Dim Act :Set Act = CreateObject("Wscript.Shell")Dim Input'-> Loop That Will Run Until a Selection Is Inputted Do'-> Get User Input  Input = InputBox( _  "Type In Some User Name To Process","","",5500,5500)'-> To Quit And Do Nothing  If Len(Input) >= 4 And LCase(Input) = "quit" Then    MsgBox "User Cancal", 4128, "User Cancel"   WScript.Quit(1)  End If '-> Process User Input If Length Is 4 Character Or More  If Len(Input) >= 4 Then '-> Confirm Before Processing User Input   If MsgBox("Is This The Correct Name You Want To Process : " & Input & vbCrLf & _   "Yes to Continue, No To Exit And Do Nothing",4132,"Confirm Action") = 6 Then'-> UnComment The 3 Lines To Make Active'   Act.Run("psexec -s " & Chr(34) & "icacls" & Chr(34) & _'   Chr(34) & " d:\profiles\"& Input &".DOMAIN.V2" & Chr(34) & _'   " /grant administrators:F /t")   WScript.Quit(2)   Else'-> User Cancel Action, MessageBox Self Closes In 3 Seconds   Act.Popup "User Cancel Action",3,"User Cancel",4128   WScript.Quit(3)   End If      End If   Loop Until Len(Input) = 1000
Link to comment
Share on other sites

Here is a VBS solution to what you wanted, a way to get user input and apply that to your command. I also added a section to where you can cancel all the action, before applying the command. I only took a guess at how the command should be in VBS

NOTES

Chr(34) = "

This Chr(34) & "icacls" & Chr(34) = ""icacls"" so it quoted around the areas that need them

Save As UserNameToAdmin.vbs

Dim Act :Set Act = CreateObject("Wscript.Shell")Dim Input'-> Loop That Will Run Until a Selection Is Inputted Do'-> Get User Input  Input = InputBox( _  "Type In Some User Name To Process","","",5500,5500)'-> To Quit And Do Nothing  If Len(Input) >= 4 And LCase(Input) = "quit" Then    MsgBox "User Cancal", 4128, "User Cancel"   WScript.Quit(1)  End If '-> Process User Input If Length Is 4 Character Or More  If Len(Input) >= 4 Then '-> Confirm Before Processing User Input   If MsgBox("Is This The Correct Name You Want To Process : " & Input & vbCrLf & _   "Yes to Continue, No To Exit And Do Nothing",4132,"Confirm Action") = 6 Then'-> UnComment The 3 Lines To Make Active'   Act.Run("psexec -s " & Chr(34) & "icacls" & Chr(34) & _'   Chr(34) & " d:\profiles\"& Input &".DOMAIN.V2" & Chr(34) & _'   " /grant administrators:F /t")   WScript.Quit(2)   Else'-> User Cancel Action, MessageBox Self Closes In 3 Seconds   Act.Popup "User Cancel Action",3,"User Cancel",4128   WScript.Quit(3)   End If      End If   Loop Until Len(Input) = 1000

ooo a alternative method.... I'm feeling the love now... :yes:

Edited by deathmage
Link to comment
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...