Need to learn more

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
MLGsuperGame414
Posts: 54
Joined: 10 Nov 2011 20:40

Need to learn more

#1 Post by MLGsuperGame414 » 22 Dec 2011 21:00

I am still new to Batch coding and well, I don't know much more then simple things like menus ect. Stuff like this

Code: Select all

Echo Select your option
Echo ------------------------
Echo.
Echo A). Computer Information
Echo B). CMD Information
Echo C). Timed Shutdown
set/p cs=Select your option;
If "%cs%"=="a" Goto :Extention1_ClusterStorm:
If "%cs%"=="b" Goto :Extention2_ClusterStorm:
If "%cs%"=="c" Goto :Extention3_ClusterStorm:
If "%cs%"=="A" Goto :Extention1_ClusterStorm:
If "%cs%"=="B" Goto :Extention2_ClusterStorm:
If "%cs%"=="C" Goto :Extention3_ClusterStorm:


I have a few things I need to learn. I am having troubles with simple command lines. For example...

Code: Select all

Syntax
      CACLS pathname [options]
    
Options:

   /T   Search the pathname including all subfolders.
   /E   Edit ACL (leave existing rights unchanged)
   /C   Continue on access denied errors.

   /G user:permission
        Grant access rights, permision can be:
          R  Read
          W  Write
          C  Change (read/write)
          F  Full control
      
   /R user
        Revoke specified user's access rights (only valid with /E).

   /P user:permission
        Replace access rights, permission can be:
          N  None
          R  Read
          W  Write
          C  Change (read/write)
          F  Full control
      
   /D user
        Deny access to user.


I'm not sure what to do with the whole /p, /d, /r not sure where to put them in the lines of code because no matter what I do it still doesn't ever work.

I'm also having troubles with IF, THEN, ELSE statements. I used them in BASIC just like this,

Code: Select all

If commandline1.txt = "Hello world" Then
Msgbox "Hello person"
Else
Msgbox "You left the textbox blank"
End If


I have come to learn that BATCH scripting isn't exactly like BASIC coding. Please just shed some light on this subject in a way that a new guy could understand.

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: Need to learn more

#2 Post by orange_batch » 22 Dec 2011 23:38

I suggest Googling for a tutorial and using http://dostips.com and http://ss64.com/nt/.

The syntax is provided for you on commands:

Code: Select all

Syntax
      CACLS pathname [options]

So, something like cacls "C:\path..." /P %username%:RWC

if syntax, single line:

Code: Select all

if 1==1 echo Hello

Else:

Code: Select all

if 1==1 (

) else (

)

Multiple conditions:

Code: Select all

if 1==1 if 2==2 (

) else (

)

if has many other functions. Check if /?. Non-equality type number comparisons must be done without quotations.

A short method of error handling:

Code: Select all

fsutil fsinfo ntfsinfo "C:"&&echo Success||echo Fail

(Checks if drive is NTFS.)

It's flexible.

Code: Select all

fsutil fsinfo ntfsinfo "C:"&&(
echo Success 1
)||(
fsutil fsinfo ntfsinfo "D:"&&(
echo Success 2
)||(
echo Both failed.
))

Post Reply