batch file for a sysinternal programme (maybe therube can help)

Off-topic posts of interest to the "Everything" community.
Post Reply
harryray2
Posts: 1104
Joined: Sat Oct 15, 2016 9:56 am

batch file for a sysinternal programme (maybe therube can help)

Post by harryray2 »

Wonder if anyone can help?

I have a small command line programme called sync from sysinternals. I need to write a batch file to run this with the parameter -r

Using Sync

Usage: sync [-r] [drive letter list]
Parameter Description
-r Flush removable drives.

Specifying specific drives (e.g. "c e") will result in Sync only flushing those drives.


I want to open a command window as admin and for the window to stay open after the operation (and also be able to reuse the window with the command ready and waiting, but not very important as I can just run the batch again)

I would also like a batch file that gives me a choice of options such as using -r and/or choice of drive letters.

I've been trying but I'm afraid it's been a long time since I've written batch files.

Thanks.
therube
Posts: 4979
Joined: Thu Sep 03, 2009 6:48 pm

Re: batch file for a sysinternal programme (maybe therube can help)

Post by therube »

A start ...

go.bat:

Code: Select all

cmd /c
set /p DRIVES=Drives to sync?  

echo  %DRIVES%
pause



if [%DRIVES%]==[] goto syncremoveableALL:


cmd /c  C:\DEV\Sysinternals\sync.exe -r %DRIVES%
@echo off  &&  goto end:


:syncremoveableALL
cmd /c  C:\DEV\Sysinternals\sync.exe -r


:end
set DRIVES=
pause

go.bat
Looks to work - except if you pass it multiple drive letters, like 'j k l' (which bombs).
I've not even considered the admin aspect.
(In UNIX, you'd just su -c go.bat & that's that.)
As written (except for it bombing), you'd have to Ctrl+C to break out of its loop.

Appears, that a (Sysinternals) SYNC -r also syncs fixed drives, irregardless?

I assume that this SYNC will do the same as Safely Remove?
(Had forgotten about Sysinternals Sync. On my end, I use a Linux sync.

Code: Select all

Usage: sync [OPTION]
Force changed blocks to disk, update the super block.

      --help     display this help and exit
      --version  output version information and exit

Report bugs to <bug-coreutils@gnu.org>.
Whether that works - at all, or if it handles removeable drives too, can't say.)


(I'm not good with [Windows] batch files [as Windows was always brain dead compared to UNIX].)
harryray2
Posts: 1104
Joined: Sat Oct 15, 2016 9:56 am

Re: batch file for a sysinternal programme (maybe therube can help)

Post by harryray2 »

Thanks, I'll give it a try...I think it's the same as Linux sync.
harryray2
Posts: 1104
Joined: Sat Oct 15, 2016 9:56 am

Re: batch file for a sysinternal programme (maybe therube can help)

Post by harryray2 »

I need to run this as an elevated prompt..any idea please?
Last edited by harryray2 on Wed Aug 04, 2021 1:05 pm, edited 1 time in total.
harryray2
Posts: 1104
Joined: Sat Oct 15, 2016 9:56 am

Re: batch file for a sysinternal programme (maybe therube can help)

Post by harryray2 »

I created a shortcut to run this as admin but is there a way to start it in an elevated window?

I've just tried it out, it seems to work well but why is there a pause after the drives to sync command?

I've taken away pause in the fourth line...it still seems to do the job OK. Is that OK?

Thanks.
Last edited by harryray2 on Wed Aug 04, 2021 5:22 pm, edited 1 time in total.
therube
Posts: 4979
Joined: Thu Sep 03, 2009 6:48 pm

Re: batch file for a sysinternal programme (maybe therube can help)

Post by therube »

Nirsoft, AdvancedRun.
You can probably automate something (possibly needed a double batch file ?) to run under an admin level User account (rather then Admin itself).

Code: Select all

advancedrun.exe   /EXEFilename  C:\batchfiles\go.bat   /RunAs 7   /runasuser therubeadmin   /runaspassword password   /run
7 says to use the specified user & pass
therubeadmin is the user. that is an admin-level user, but not "Administrator", but is probably sufficient.
password, is therubeadmin's password
/run, says to actually run the command rather then bringing up the GUI


As far as the PAUSE, they're a simple way to pause operations (that otherwise might just go "poof"), allowing you to catch errors... Likewise, you can set ECHO OFF (or ON) as desired. So if you don't want the PAUSE, remove it.

but is probably sufficient
Actually, it probably is not (if you're wanting to sync your "system" drive).
Most likely you are going to have to elevate (which advancedrun can also do) - but you're going to be hit with a UAC prompt.
harryray2
Posts: 1104
Joined: Sat Oct 15, 2016 9:56 am

Re: batch file for a sysinternal programme (maybe therube can help)

Post by harryray2 »

Yes, thanks, I've already got advanced run but I've never used it.

One of the problems in using CMD (which thankfully I don't have to do often) is that when run as admin one can't drag and drop.

I'm afraid this is something that's always confused me, the difference between running as Admin or running as Administrator. I log on as Administrator.
harryray2
Posts: 1104
Joined: Sat Oct 15, 2016 9:56 am

Re: batch file for a sysinternal programme (maybe therube can help)

Post by harryray2 »

How do I put an enter command in the BAT file?

I have to press enter after the 'drives to sync?' dialogue...

I think I got it...I deleted set p

I don't suppose there's any way of bypassing the UAC on this as I'm using an elevated window?
My odd solution at the moment is to use an auto mouse clicker :0)

Thanks.
harryray2
Posts: 1104
Joined: Sat Oct 15, 2016 9:56 am

Re: batch file for a sysinternal programme (maybe therube can help)

Post by harryray2 »

Could I pick your brains again please.

A couple of things...I want to be able to run something in a command box as admin. I have a context menu (send to) programme that enables me to send a file path to a cmd box, rather than opening a cmd box and pasting in the path and filename.
What I want is to be able to right click and send it to elevated command box.

Secondly is it possible to create a batch file that enables me to hide/unhide hidden files rather than doing it through folder options in Windows 7?
I've actually got a couple of batch files for it already but it involves restarting explorer...I'm wondering if it can be done without the restart.

This is the batch:
REG ADD "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /V Hidden /T REG_DWORD /D 0 /F

taskkill /f /im explorer.exe
start explorer.exe

Thanks.
therube
Posts: 4979
Joined: Thu Sep 03, 2009 6:48 pm

Re: batch file for a sysinternal programme (maybe therube can help)

Post by therube »

batch file that enables me to hide/unhide hidden files rather than doing it through folder options in Windows 7?
I guess by that you mean by & for Windows Explorer.

One of the first things I do on a system is to enable (display of) Hidden/System files for Windows Explorer.
(I have no reason to have them hidden.)
And that said, I virtually never use Windows Explorer, instead a real file manager, which of course has a setting to 'hide files and directories with hidden or system attribute' (which of course works regardless of any Windows Explorer settings).

Batch file (or otherwise) for the Windows Explorer end, no clue.

---
I have a context menu (send to) programme that enables me to send a file path to a cmd box, rather than opening a cmd box and pasting in the path and filename.
Not a paste, but if you had an elevated command prompt window open, you could drag a filename (say from elevated Everything) to the command prompt window (which pastes it).
(Probably not a good way to go about it.)

(It would have to be elevated to elevated or not elevated to not elevated.)

-

You could see if you could incorporate a paste into your SendTo [contents ?].
(I'm not really familiar with that paste, & only gave it a cursory look. And I'm thinking that going from normal user to an elevated (command prompt), it's apt to not work anyhow ? Likely to work once you're in the elevated state, but not between the two ?)
Post Reply