Post by xxgeek on Feb 6, 2021 8:07:03 GMT
For New Users of Just Basic to help get jobs done while learning the syntax and structure of JB, and for the users of JB who Just (pun intended) didn't know.
Using CMD.exe when Just Basic can't do the job, or your skill with JB isn't quite there yet, and you need to get the job done anyway you can..
One site of many for command reference.
docs.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands
Windows command line commands can be connected in such a way that they run directly after one other. This can be controlled using (&), && and || . It’s possible to only run the second command if the first was successful. Or, you can set up the exact opposite as well: The second command is only run if the first doesn’t work. (||). Both options can even be combined so that there’s an either-or string of commands:
CommandA & CommandB (the second command is run directly after the first)
CommandA && CommandB (the second command is only run if the first was successful)
Command A || CommandB (the second command is only run if the first was not successful)
CommandA && CommandB || CommandC (the second command is only run if the first was successful, otherwise the third command is run)
You can hide the command window when it opens.
You can edit, create, delete registry keys using cmd.exe.
You can execute any .exe, .bat, .cmd, .ps1, or any other executable file Windows has support for.
A couple of quick example for use with Just Basic.
'make a new directory, or overwrite an existing one.
' the path needs to be wrapped in "quotes" when there are spaces in 'any' name on the path.
qq$ = char$(34) ' ASCII for " - the quote symbol
DirPath$ = "c:\some folder\another folder\newfoldername"
NewDirPath$ ="e:\some folder\another folder\newfolder"
run "cmd.exe /c mkdir ";qq$;DirPath$;qq$
'when there are no spaces no quotes are necessay, but may be used if you like to type.
DirPath$ = "c:\somefolder\anotherfolder\newfoldername"
run "cmd.exe /c mkdir ";qq$;DirPath$;qq$
or
run "cmd.exe /c mkdir ";DirPath$
or
run "cmd.exe /c mkdir ";"c:\somefolder\anotherfolder\newfolder"
'Likewise for all the commands cmd can muster.
eg:
run "cmd.exe /c copy ";qq$;DirPath$;qq$;" ";qq$;NewDirPath$;qq$
'or when no spaces exist in the path
run "cmd.exe /c copy ";DirPath$;" ";NewDirPath$
'notice the space between the dir paths above, they separate the "from" , and "to" of the copy command.
'or
run "cmd.exe /c copy ";"c:\somefolder\anotherfolder\existingfolder";" ";e:\somefolder\anotherfolder\newfolder"
The above commands for mkdir, and copy will create when no existing file or dir exists, but if they do already exist they will be overritten so be careful.
This can be worked around with different switches, but not the scope of this tip post
Please see the link above for further use of the commandline.
Using CMD.exe when Just Basic can't do the job, or your skill with JB isn't quite there yet, and you need to get the job done anyway you can..
One site of many for command reference.
docs.microsoft.com/en-us/windows-server/administration/windows-commands/windows-commands
Windows command line commands can be connected in such a way that they run directly after one other. This can be controlled using (&), && and || . It’s possible to only run the second command if the first was successful. Or, you can set up the exact opposite as well: The second command is only run if the first doesn’t work. (||). Both options can even be combined so that there’s an either-or string of commands:
CommandA & CommandB (the second command is run directly after the first)
CommandA && CommandB (the second command is only run if the first was successful)
Command A || CommandB (the second command is only run if the first was not successful)
CommandA && CommandB || CommandC (the second command is only run if the first was successful, otherwise the third command is run)
You can hide the command window when it opens.
You can edit, create, delete registry keys using cmd.exe.
You can execute any .exe, .bat, .cmd, .ps1, or any other executable file Windows has support for.
A couple of quick example for use with Just Basic.
'make a new directory, or overwrite an existing one.
' the path needs to be wrapped in "quotes" when there are spaces in 'any' name on the path.
qq$ = char$(34) ' ASCII for " - the quote symbol
DirPath$ = "c:\some folder\another folder\newfoldername"
NewDirPath$ ="e:\some folder\another folder\newfolder"
run "cmd.exe /c mkdir ";qq$;DirPath$;qq$
'when there are no spaces no quotes are necessay, but may be used if you like to type.
DirPath$ = "c:\somefolder\anotherfolder\newfoldername"
run "cmd.exe /c mkdir ";qq$;DirPath$;qq$
or
run "cmd.exe /c mkdir ";DirPath$
or
run "cmd.exe /c mkdir ";"c:\somefolder\anotherfolder\newfolder"
'Likewise for all the commands cmd can muster.
eg:
run "cmd.exe /c copy ";qq$;DirPath$;qq$;" ";qq$;NewDirPath$;qq$
'or when no spaces exist in the path
run "cmd.exe /c copy ";DirPath$;" ";NewDirPath$
'notice the space between the dir paths above, they separate the "from" , and "to" of the copy command.
'or
run "cmd.exe /c copy ";"c:\somefolder\anotherfolder\existingfolder";" ";e:\somefolder\anotherfolder\newfolder"
The above commands for mkdir, and copy will create when no existing file or dir exists, but if they do already exist they will be overritten so be careful.
This can be worked around with different switches, but not the scope of this tip post
Please see the link above for further use of the commandline.