It is currently March 29th, 2024, 12:15 am

Is there a way to overwrite a text file?

Discuss the use of Lua in Script measures.
jav26122
Posts: 26
Joined: February 9th, 2015, 8:45 pm

Re: Is there a way to overwrite a text file?

Post by jav26122 »

jsmorley wrote:Create a batch file or vbs script file to start GPU-Z from the Startup folder, instead of just running the shortcut for GPU-Z...

Have that batch or script file delete the log file, then start GPU-Z.

That way any time you reboot, the log is cleared out.

Yeah... I don't really reboot that often... Is there a way I can maybe like close gpu-z every 12 hours or something, delete the file, and then re-open it?
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Is there a way to overwrite a text file?

Post by jsmorley »

You can run the batch or vbs as a scheduled task in Windows, or even just have the skin itself run the batch or vbs every time the skin is "refreshed".
jav26122
Posts: 26
Joined: February 9th, 2015, 8:45 pm

Re: Is there a way to overwrite a text file?

Post by jav26122 »

This is the first time I've ever done something with rainmeter... How exactly would I stop gpu-z from within the skin lua script and then restart it?
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Is there a way to overwrite a text file?

Post by jsmorley »

The best bet is to use the RunCommand plugin to execute taskkill.exe to stop GPU-Z then delete the file, then start GPU-Z.

http://rainmeter.net/forum/viewtopic.php?p=92974#p92974

Give me a few minutes, and I can work up a little example.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Is there a way to overwrite a text file?

Post by jsmorley »

Ok.

It was a little tricky, since GPU-Z requires that any shell cmd.exe using taskkill.exe to stop it have administrator access, and that just causes UAC popups that are really annoying.

So I wrote a little AutoIt app which you can download here:
GPUZKill.zip
Here is the AutoIt code, so you can see what it does:

Code: Select all

#NoTrayIcon

If $CmdLine[0] < 3 Then
	Exit
EndIf

$Process = $CmdLine[1]
$Log = $CmdLine[2]
$Command = $CmdLine[3]

While ProcessExists($Process)
	ProcessClose($Process)
WEnd

FileDelete ($Log)
ShellExecute($Command)

Exit
Which will do the following:

1) Kill GPU-Z based on the first command line parameter passed to it.
2) Delete the log file based on the second command line parameter passed to it.
3) Start GPU-Z based on the third command line passed to it.

So with this skin code:

Code: Select all

[Rainmeter]
Update=1000
OnRefreshAction=["#@#GPUZKill.exe" "#Process#" "#LogFile#" "#Command#"]

[Variables]
Process=GPU-Z.exe
LogFile=C:\SomePath\GPU-Z Sensor Log.txt
Command=C:\SomePath\GPU-Z.exe
Anytime that skin is loaded or refreshed, Rainmeter will execute GPUZKill.exe in the @Resources folder of your skin, and pass those variables to it on the command line.

GPUZKill.exe will:

Based on the [Variable] #Process#, close that executable in Windows.
Based on the [Variable] #LogFile#, delete that log file.
Based on the [Variable] #Command#, restart GPU-Z.

Be sure you define everything correctly in [Variables]. In particular, if you run GPU-Z in "stand-alone" mode, (its "sorta portable" mode) the process and executable name will be something like GPU-Z.0.8.1.exe, not just GPU-Z.exe.

Let me know if you have any questions.
You do not have the required permissions to view the files attached to this post.
jav26122
Posts: 26
Joined: February 9th, 2015, 8:45 pm

Re: Is there a way to overwrite a text file?

Post by jav26122 »

Alright so with this it stops gpu-z, deletes the file, and restarts gpu-z, but it only does it once whenever the skin is loaded and the UAC prompt comes up everytime... What am I doing wrong?

Code: Select all

[Rainmeter]
Background=..\Images\bg_ram_cpu.png
Update=1000
OnRefreshAction=["C:\path\GPUZKILL\GPUZKill.exe" "#Process#" "#LogFile#" "#Command#"]

[Variables]
@Include="..\UserVariables.inc"
Process=GPU-Z.exe
LogFile=D:\path\GPU-Z Sensor Log.txt
Command=C:\Program Files (x86)\GPU-Z\GPU-Z.exe
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Is there a way to overwrite a text file?

Post by jsmorley »

jav26122 wrote:Alright so with this it stops gpu-z, deletes the file, and restarts gpu-z, but it only does it once whenever the skin is loaded and the UAC prompt comes up everytime... What am I doing wrong?

Code: Select all

[Rainmeter]
Background=..\Images\bg_ram_cpu.png
Update=1000
OnRefreshAction=["C:\path\GPUZKILL\GPUZKill.exe" "#Process#" "#LogFile#" "#Command#"]

[Variables]
@Include="..\UserVariables.inc"
Process=GPU-Z.exe
LogFile=D:\path\GPU-Z Sensor Log.txt
Command=C:\Program Files (x86)\GPU-Z\GPU-Z.exe
Nothing. That is the expected behavior. OnRefreshAction is only fired when the skin is first loaded, and any time it is "refreshed". As to the UAC prompt, you are not going to avoid that. GPU-Z is very hardware "intimate", and Windows is going to prompt you every time it is run.

You really sure GPU-Z is the way you want to go? To each his own, but I sure prefer using HWiNFO and the HWiNFO plugin for Rainmeter, so I'm not parsing huge log files on every skin update.

http://rainmeter.net/forum/viewtopic.php?f=18&t=13670

Has pretty much all the GPU sensor info you might want.
1.jpg
You do not have the required permissions to view the files attached to this post.