Jump to content

Quser using .bat

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
mojo1979

mojo1979

    Newbie

  • Members
  • Pip
  • 3 posts
Hi,

I have written a .bat file that parses data to a text file, which is then displayed in an html page. Basically the .bat file uses the quser command to query logged on users of servers. Here's an example of the .bat:

cd C:\Windows\System32
Echo MODWK136 >> S:\Query_RDP_MODWK\Result_Quser.txt
quser.exe /Server:MODWK136 >> S:\Query_RDP_MODWK\Result_Quser.txt
cd C:\Windows\System32
Echo MODWK137 >> S:\Query_RDP_MODWK\Result_Quser.txt
quser.exe /Server:MODWK137 >> S:\Query_RDP_MODWK\Result_Quser.txt

If I manually run the .bat it works and the correct info in displayed in the html page. However what I want it to do is to refresh every 30 mins so that the info in the Result_Quser.txt file is updated, hence showing the updated info in the html page.

However if I then run the .bat a second time it doesn't work because it only amends the Result_Quser.txt file rather than overwriting it, hence the html page shows the original data not the new. I have tried using > instead of >> but to no avail.

So my question is how to I overwrite the Result_Quser.txt file rather than amending it. I also want the .bat to run automatically every 30mins - what's the best way to do this - via the .bat?

Thanks for any help!

Steve

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Why not delete the file before redirecting the results into it?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
mojo1979

mojo1979

    Newbie

  • Members
  • Pip
  • 3 posts
Can I write this delete into the .bat?

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You should be able to, yes.
del S:\Query_RDP_MODWK\Result_Quser.txt
cd C:\Windows\System32
Echo MODWK136 >> S:\Query_RDP_MODWK\Result_Quser.txt
quser.exe /Server:MODWK136 >> S:\Query_RDP_MODWK\Result_Quser.txt
cd C:\Windows\System32
Echo MODWK137 >> S:\Query_RDP_MODWK\Result_Quser.txt
quser.exe /Server:MODWK137 >> S:\Query_RDP_MODWK\Result_Quser.txt

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
mojo1979

mojo1979

    Newbie

  • Members
  • Pip
  • 3 posts
Thanks this worked...

I guess I should just use tash scheduler to automate the running of the .bat...