bat. exe. help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
adamball
Posts: 3
Joined: 11 May 2012 07:43

bat. exe. help

#1 Post by adamball » 11 May 2012 07:57

hello im new on here and i need some help
my mind has been screwing around and around but i cant put my finger on it :?:
everytime i get closer their is something stopping me from doing it
right i tried to get my computer to run this bat file before i go onto my computer and do other stuff on it
i put it in the startup folder even made it a exe. but both dont work so well because i need admin control
exe. doesnt work bc its not compatible with the version of windows


@echo off

del /s /q "%userprofile%\cookies\*.*"

del /f /q %windir%\Prefetch\*.*

del /f /q %windir%\Temp\*.*

del /f /q "%userprofile%\local settings\temp\*.*"

del /f /q "%userprofile%\local settings\temporary internet files\*.*"

sleep 60

rd /s c:\$Recycle.Bin

rd /s c:\recycler

sleep 30

freemem=space(128000000).

chkdsk c: /r

chkdsk c: /f

sleep 60

defrag c: -a -f -v

im screwed and dier assitance
please help
i want this bat to run on all windows types after i get it to work on windows 7
dont worry about the sleep bits on the echo i know they dont work
and also i like to make

rd /s c:\$Recycle.Bin

rd /s c:\recycler

to auto recycle not to ask me all the time i go on the computer

thank you for your time in looking at this and please post a comment if you can help

sincerally
adam

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: bat. exe. help

#2 Post by foxidrive » 11 May 2012 09:09

You can't do several of those things without admin privileges.

adamball
Posts: 3
Joined: 11 May 2012 07:43

Re: bat. exe. help

#3 Post by adamball » 11 May 2012 15:46

foxidrive wrote:You can't do several of those things without admin privileges.

is their anyway i can put them into a exe file or some other type file which i can use
instead so i can have the admin privileges

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: bat. exe. help

#4 Post by Fawers » 11 May 2012 15:58

Can you open CMD with ADM privileges?
If yes, do you mind having the batch running on a specific time instead of Logging on and running it?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: bat. exe. help

#5 Post by foxidrive » 11 May 2012 16:44

You can right click a batch file to run it with admin privs. An exe file doing the same things would also have to be launched the same way.

adamball
Posts: 3
Joined: 11 May 2012 07:43

Re: bat. exe. help

#6 Post by adamball » 11 May 2012 17:26

im going to try vbs file

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: bat. exe. help

#7 Post by abc0502 » 11 May 2012 17:35

Gaining Admin Privilege in windows 7 is very easy, I use it all the time, here is how:

If your batch file is too big u make two files one is a vbscript and write in it just two lines:
Set UAC = CreateObject("Shell.Application")
UAC.ShellExecute "Batch.bat", "", "", "runas", 1


And make ur batch file, name it the same name in the vbscript "the red name" and put the two in the same place.

and now run the vbscript by double click "without Run As Administartor"
and the batch will run in admin mode.

to test the vbscript replace the Batch.bat with cmd.exe and the command prompt will run in Administrator Rights

The Second option is when running small batch that do few commands u just make one batch that create the vbscript and create ur batch that contain ur code and then it run the vbscript that run ur batch.

Hope u use that in good :wink:

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: bat. exe. help

#8 Post by foxidrive » 11 May 2012 18:28

Thanks from me too abc0502 - that will be handy.

Code: Select all

Set UAC = CreateObject("Shell.Application")
UAC.ShellExecute "Batch.bat", "", "", "runas", 1

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: bat. exe. help

#9 Post by abc0502 » 11 May 2012 20:13

foxidrive wrote:Thanks from me too abc0502 - that will be handy.

Code: Select all

Set UAC = CreateObject("Shell.Application")
UAC.ShellExecute "Batch.bat", "", "", "runas", 1

I'm glade u found that handy ,In fact this is not mine i found it before here : viewtopic.php?p=14060#p14060 By jaheaga
it was giving me errors some times so i took the vb code and run it separately to avoid the errors. :)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: bat. exe. help

#10 Post by foxidrive » 12 May 2012 19:32

abc0502, I tried the code today and while it works, it generates a UAC prompt to run the VBS code too.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: bat. exe. help

#11 Post by abc0502 » 12 May 2012 23:42

foxidrive wrote:abc0502, I tried the code today and while it works, it generates a UAC prompt to run the VBS code too.

I apologize for this error, I found my uac turned off so i wasn't getting that prompt, as soon i find a way around it i will get back to you. :oops:

aGerman
Expert
Posts: 4741
Joined: 22 Jan 2010 18:01
Location: Germany

Re: bat. exe. help

#12 Post by aGerman » 13 May 2012 08:35

The "runas" verb will always pop up the prompt if the UAC is turned on. That's the way M$ developed Vista/Win7 for safety reasons. There is no workaround.

If an application causes the UAC prompt and you don't need to run it in elevated mode then you could "RunAsInvoker". That can be done by setting the __COMPAT_LAYER environment variable.
Example:

Code: Select all

@echo off &setlocal
set "__COMPAT_LAYER=RunAsInvoker"
start "" "regedit.exe"

The child environment inherits that variable. Now you don't get the UAC prompt, regedit runs in nonelevated mode though (you're not allowed to change anything but your own HKCU).

Regards
aGerman

Post Reply