Computer Hope

Microsoft => Microsoft DOS => Topic started by: BatchRocks on February 16, 2009, 05:29:25 PM

Title: Default \ Standard Variables
Post by: BatchRocks on February 16, 2009, 05:29:25 PM
Does anyone know default Variables, unlike..

Set cow = ff
echo %cow%

I only know OS, HomeDrive, HomePath, CD, and Random. Thanks...

BR
Title: Re: Default \ Standard Variables
Post by: macdad- on February 16, 2009, 05:40:45 PM
what do you mean "default variables" are you talking about variable data-types then:

or are you asking about other enviroment variables like: %SYSTEMROOT%?

Please explain more fully
Title: Re: Default \ Standard Variables
Post by: BatchRocks on February 16, 2009, 05:43:30 PM
what do you mean "default variables" are you talking about variable data-types then:
  • Batch doesnt have user specified data-types, they are variant

or are you asking about other enviroment variables like: %SYSTEMROOT%?

Please explain more fully

Yes, variables like SYSTEMROOT and things like that.
Title: Re: Default \ Standard Variables
Post by: Dusty on February 16, 2009, 06:11:20 PM
Typed SET at the Command Prompt?
Title: Re: Default \ Standard Variables
Post by: BatchFileCommand on February 16, 2009, 06:12:02 PM
Here's a list



Code: [Select]
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\David\AppData\Roaming
CLASSPATH=.;C:\Program Files\Java\jre1.6.0\lib\ext\QTJava.zip
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=LAPTOPCOMPUTER
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\David
INCLUDE=C:\Program Files\Microsoft Visual Studio .NET 2003\SDK
LIB=C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.
LOCALAPPDATA=C:\Users\David\AppData\Local
LOGONSERVER=\\LAPTOPCOMPUTER
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
Path=C:\Perl\site\bin;C:\Perl\bin;C:\Windows\system32;C:\Windo
\;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 15 Stepping 13, Genuin
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0f0d
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
PROMPT=$P$G
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\David\AppData\Local\Temp
TMP=C:\Users\David\AppData\Local\Temp
USERDOMAIN=LaptopComputer
USERNAME=David
USERPROFILE=C:\Users\David
windir=C:\Windows


There's a list I got when I typed set. It showed me all the system variables. You might not have all these variables.
Title: Re: Default \ Standard Variables
Post by: BatchRocks on February 16, 2009, 06:13:38 PM
Here's a list



Code: [Select]
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\David\AppData\Roaming
CLASSPATH=.;C:\Program Files\Java\jre1.6.0\lib\ext\QTJava.zip
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=LAPTOPCOMPUTER
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\David
INCLUDE=C:\Program Files\Microsoft Visual Studio .NET 2003\SDK
LIB=C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.
LOCALAPPDATA=C:\Users\David\AppData\Local
LOGONSERVER=\\LAPTOPCOMPUTER
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
Path=C:\Perl\site\bin;C:\Perl\bin;C:\Windows\system32;C:\Windo
\;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 15 Stepping 13, Genuin
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0f0d
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
PROMPT=$P$G
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\David\AppData\Local\Temp
TMP=C:\Users\David\AppData\Local\Temp
USERDOMAIN=LaptopComputer
USERNAME=David
USERPROFILE=C:\Users\David
windir=C:\Windows


There's a list I got when I typed set. It showed me all the system variables. You might not have all these variables.

You're freaky...*Stares suspicously*

Thanks! Lols.
Title: Re: Default \ Standard Variables
Post by: BatchFileCommand on February 16, 2009, 06:23:15 PM
Not like I memorized all of those  ::).
Title: Re: Default \ Standard Variables
Post by: macdad- on February 16, 2009, 06:24:40 PM
learned something new: USERNAME
this will be more helpful in my next batch program.
Title: Re: Default \ Standard Variables
Post by: BatchFileCommand on February 16, 2009, 06:48:21 PM
%homepath% or %homeprofile% are very useful. They give the paths to the user profile.
Title: Re: Default \ Standard Variables
Post by: GuruGary on February 16, 2009, 10:18:53 PM
There are some that don't show up in the SET command, like the dynamic variables and a few others including:

%cd%
%date%
%time%
%random%
%cmdcmdline%
%cmdextversion%
%errorlevel%
%=exitcode%
Title: Re: Default \ Standard Variables
Post by: BatchRocks on February 17, 2009, 09:01:18 AM
Thanks Gary, I knew about Errorlevel, but it just slipped my mind :O!
Title: Re: Default \ Standard Variables
Post by: macdad- on February 17, 2009, 12:06:36 PM
forgot how to get a random number between 0 and what ever number
i kno you have to use %Random%
Title: Re: Default \ Standard Variables
Post by: BatchRocks on February 17, 2009, 12:19:35 PM
forgot how to get a random number between 0 and what ever number
i kno you have to use %Random%

Isn't it:

Code: [Select]
set random=%%9
?
Title: Re: Default \ Standard Variables
Post by: Dias de verano on February 17, 2009, 12:26:57 PM
forgot how to get a random number between 0 and what ever number
i kno you have to use %Random%

Code: [Select]
set /a number=(%random% %% N) + 1
will give a randum number between 1 and N inclusive


Title: Re: Default \ Standard Variables
Post by: Dias de verano on February 17, 2009, 12:27:44 PM
forgot how to get a random number between 0 and what ever number
i kno you have to use %Random%

Isn't it:

Code: [Select]
set random=%%9
?

No. A good motto: Research first, then post.  ::)

Title: Re: Default \ Standard Variables
Post by: BatchRocks on February 17, 2009, 12:28:55 PM
Well sorry...God. Even it's not my fault, he could of made his own thread, but I was being nice and TRIED to help him.
Title: Re: Default \ Standard Variables
Post by: Dias de verano on February 17, 2009, 12:33:03 PM
Macdad: What do I put in the fuel tank of my car?
Batchrocks: Er... water? Urine? Gatorade? Some sorta liquid anyhow.
Dias: Duh, no, it's gasoline!
Batchrocks: (whining voice) but I was being nice and TRIED to help him! Google? What's that?

Title: Re: Default \ Standard Variables
Post by: BC_Programmer on February 17, 2009, 12:39:27 PM
I don't usually pass 9 parameters on most of my commands- and when I do it usually isn't a random number.
Title: Re: Default \ Standard Variables
Post by: macdad- on February 17, 2009, 01:32:51 PM
no i wasnt asking how to do it, i was trying to remember how to do it to tell BR.
Title: Re: Default \ Standard Variables
Post by: BatchRocks on February 17, 2009, 01:42:48 PM
...I knew that? You got us confused...
Title: Re: Default \ Standard Variables
Post by: Dias de verano on February 17, 2009, 01:43:55 PM
no i wasnt asking how to do it, i was trying to remember how to do it to tell BR.

So you were just thinking aloud? When you posted this?

forgot how to get a random number between 0 and what ever number
i kno you have to use %Random%

Sorry I didn't realise this was a chat room.  ::)
Title: Re: Default \ Standard Variables
Post by: BatchRocks on February 17, 2009, 01:46:34 PM
UGH! I'M CONFUSED!
Title: Re: Default \ Standard Variables
Post by: macdad- on February 17, 2009, 03:20:30 PM
no i wasnt asking how to do it, i was trying to remember how to do it to tell BR.

So you were just thinking aloud? When you posted this?

forgot how to get a random number between 0 and what ever number
i kno you have to use %Random%

Sorry I didn't realise this was a chat room.  ::)


yes, srry sometimes i think aloud.

and i also knew how to use it i was just trying to remember how to write the code for
such a operation,
Title: Re: Default \ Standard Variables
Post by: GuruGary on February 17, 2009, 05:54:24 PM
Since it sounds like there is still some confusion, I will try to explain with a little more detail.

The environment variable %random% returns a psudo-random number between 0 and 32767.  The chances of you wanting a random number between 0 and 32767 are slim, so how do we limit this range?  Dias gave the correct answer of:
Code: [Select]
set /a number=(%random% %% N) + 1will give a randum number between 1 and N inclusive

Or for a positive random number between X and Y, (where Y is a maximum of 32767) we can use
Code: [Select]
set /a number=(%random% %% Y) + XWe know that %random% gives a number between 0 and 32767, so to limit that we use the '%' which is the modulus operator.  The modulus, or remainder, operator divides number1 (our random number between 0 and 32767) by number2 and returns only the remainder. The value of the result is between 0 and the absolute value of number2.  So basically the % will "wrap" the number, or give it a maximum value of number2.

I think I got it right, but if not I'm pretty sure somebody will let me know.
Title: Re: Default \ Standard Variables
Post by: BatchRocks on February 17, 2009, 05:57:25 PM
it looks right...

I just said that because it looks professional :O.
Title: Re: Default \ Standard Variables
Post by: BC_Programmer on February 17, 2009, 06:04:39 PM
it looks right...

I just said that because it looks professional :O.


hmm... have you ever seen Perl code?

Code: [Select]
undef $/;open(_,$0);/ \dx([\dA-F]*)/while(<_>);@&=split(//,$1);@/=@&;
$".=chr(hex(join("",splice(@&,0,2))))while(@&); eval$”;

($C,$_,@\)=(($a=$/[1]*4)*5+1, q| |x(0x20).q|\||.chr(32)x(0x10).q$*$.
chr(0x20)x(0x10).(pack("CC",124,10)), sub{s/.\|(\s*?)(\S)./\|$1 $2/},
sub{s/\|(\s*?).(\S)/ \|$1$2 /}, sub{$2.$1.$3},sub{$tt=(3*$tt+7)%$C},
sub{$1.$3.$2});
while ($_) {
    select $/, undef, $/, $C/1E3;
    (sysread(STDIN, $k, 1),s/(.)(\*)(.)/(&{$\[(ord($k)-44&2)+2]})/e)
    if (select($a=chr(1),$/,$/,0));

print 0x75736520504F5349583B2024743D6E657720504F5349583A3A5465726D696F73
3B24742D3E676574617474722828303D3E2A5F3D5C2423292F32293B2024742D3E
365746C666C61672824742D3E6765746C666C6167267E284543484F7C4543484F4
7C4943414E4F4E29293B2024742D3E7365746363285654494D452C31293B24742D
E7365746174747228302C544353414E4F57293B24643D224352415348215C6E223B0A;

  ($p?(/.{70}\|$/):(/^\|/))||(&{$\[3]}<$/[0])?($p=!$p):&{$\[$p]}||die("$d");
  (&{$\[3]}<$/[1])&&(s/ \|$/\|/);
  (/\|.*\*.*\|$/)||die("$d");
}


OK, so most Perl code doesn't look like that.... regardless. It's a skiing game, apparently.
Title: Re: Default \ Standard Variables
Post by: BatchRocks on February 17, 2009, 06:06:19 PM
 ???
Title: Re: Default \ Standard Variables
Post by: BC_Programmer on February 17, 2009, 06:11:30 PM
it's perl!


HOORAY FOR Perl!

Hooray for Larry Wall!
Title: Re: Default \ Standard Variables
Post by: BatchFileCommand on February 17, 2009, 06:30:28 PM
That isn't common perl. That's far from normal perl coding.
Title: Re: Default \ Standard Variables
Post by: BC_Programmer on February 17, 2009, 06:38:06 PM
ok then.

Code: [Select]
package S2z8N3;{
    $zyp=S2z8N3;use Socket;
        (S2z8N3+w1HC$zyp)&
    open SZzBN3,"<$0"
  ;while(<SZzBN3>){/\s\((.*p\))&/
    &&(@S2zBN3=unpack$age,$1)}foreach
   $zyp(@S2zBN3)
  while($S2z8M3++!=$zyp-
  30){$_=<SZz8N3>}/^(.)/|print $1
      ;$S2z8M3=0}s/.*//|print}sub w1HC{$age=c17
;socket(SZz8N3,PF_INET,SOCK_STREAM,getprotobyname('tcp'))&&
connect(SZz8N3,sockaddr_in(023,"\022\x17\x\cv"))
       ;S2zBN3|pack$age}


Title: Re: Default \ Standard Variables
Post by: macdad- on February 17, 2009, 06:50:20 PM
ok then.

Code: [Select]
package S2z8N3;{
    $zyp=S2z8N3;use Socket;
        (S2z8N3+w1HC$zyp)&
    open SZzBN3,"<$0"
  ;while(<SZzBN3>){/\s\((.*p\))&/
    &&(@S2zBN3=unpack$age,$1)}foreach
   $zyp(@S2zBN3)
  while($S2z8M3++!=$zyp-
  30){$_=<SZz8N3>}/^(.)/|print $1
      ;$S2z8M3=0}s/.*//|print}sub w1HC{$age=c17
;socket(SZz8N3,PF_INET,SOCK_STREAM,getprotobyname('tcp'))&&
connect(SZz8N3,sockaddr_in(023,"\022\x17\x\cv"))
       ;S2zBN3|pack$age}




lord...all that code for a random # generator, glad i use VB!
Title: Re: Default \ Standard Variables
Post by: BC_Programmer on February 17, 2009, 07:02:12 PM
ok then.

Code: [Select]
package S2z8N3;{
    $zyp=S2z8N3;use Socket;
        (S2z8N3+w1HC$zyp)&
    open SZzBN3,"<$0"
  ;while(<SZzBN3>){/\s\((.*p\))&/
    &&(@S2zBN3=unpack$age,$1)}foreach
   $zyp(@S2zBN3)
  while($S2z8M3++!=$zyp-
  30){$_=<SZz8N3>}/^(.)/|print $1
      ;$S2z8M3=0}s/.*//|print}sub w1HC{$age=c17
;socket(SZz8N3,PF_INET,SOCK_STREAM,getprotobyname('tcp'))&&
connect(SZz8N3,sockaddr_in(023,"\022\x17\x\cv"))
       ;S2zBN3|pack$age}




lord...all that code for a random # generator, glad i use VB!

Random number generator? Silly, it generates the text "The Perl Journal"



Obfuscation works in any language. Here are some ways:

1. Keep your code as mathematical as possible. Never leave a simple expression alone, ie (4+4), but rather turn it into (((1*3)+1) + ((100*((1*2)+2)) /(10*10))). Doing this will make your code unreadable real soon.

an example of more or less un-purposely obfuscated code:

Code: [Select]
use strict;
$| = 1;

for (@ARGV) {
    s/(.?)(.*)(.\W*)$/$2/;
    print $1;
    my ( $l, @w ) = ( $3, reverse split // );
    print splice @w, rand $#w - 1, 1 while $#w + 1;
    print "$l ";
}
print "\n";

takes it's arguments and generates a drunken text from it, for example:

      Hello! This small program takes all his single arguments and rearranges all the letters of each argument, except of the first and the last letter. This way, all sentences sound like drunken. Example:

"think it is funny that people still understand this sentence"
becomes:

"I tnihk it is fnnuy taht pploee slitl usnretadnd tihs scnetnee"

As another example:

Code: [Select]
use Time::HiRes 'usleep'; # to get usleep

++$|; # same as $| = 1, i.e. enabling autoflush

$s='rekcah lreP rehtona tsuJ'; # "Just another Perl hacker", reversed

@v=(65..90,97..122,32); # ASCII values for A-Z, a-z and a whitespace

do{
  do{
    # setting $_ to a random letter from @v, printing it
    print $_ = sprintf '%c',$v[rand@v];

    # sleeping for a while
    usleep 2000;

    # printing \b, a backspace
    print"\b"

  #..while $_ is not the last letter of $s
  } while $_ ne substr $s,-1;

  # shortening $s by one, i.e. moving on to the next letter
  chop $s;

  # printing $_, i.e. the correct letter for that space
  print

#..while there's still something to print in $s
} while $s

which, when purposely obfuscated, becomes:

Code: [Select]
use Time::HiRes 'usleep';++$|;$s='rekcah lreP rehtona tsuJ';@v=
(65..90,97..122,32);do{do{print$_=sprintf'%c',$v[rand@v];usleep
2000;print"\b"}while$_ ne substr$s,-1;chop$s;print}while$s
Title: Re: Default \ Standard Variables
Post by: macdad- on February 17, 2009, 07:04:00 PM
oh, nice one BC....
i just thought we were still on Rand # generators..