Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit cffc13d

Browse files
authored
Merge pull request #77 from KnifMelti/main
Mods Template/Functions - App as User and Replace text in file
2 parents 4e2a913 + b493a35 commit cffc13d

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

mods/_AppID-template.ps1

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<# ARRAYS/VARIABLES #>
2-
#App to Run ($RunWait = $False if it shouldn't be waited for)
3-
$Run = ""
2+
#App to Run (as SYSTEM)
3+
#$RunWait = $False if it shouldn't be waited for completion
4+
$RunSystem = ""
45
$RunSwitch = ""
56
$RunWait = $True
67

@@ -44,15 +45,28 @@ $DelFile = @("")
4445
$CopyFile = ""
4546
$CopyTo = ""
4647

48+
#Find/Replace text in file
49+
#Example:
50+
#$File = "C:\dummy.txt"
51+
#$FindText = 'brown fox'
52+
#$ReplaceText = 'white fox'
53+
$File = ""
54+
$FindText = ''
55+
$ReplaceText = ''
56+
4757
#Grant "Modify" for directory/file to "Authenticated Users" - multiple: "dir1","dir2"
4858
$GrantPath = @("")
4959

60+
#App to Run (as current logged-on user)
61+
$RunUser = ""
62+
$User = $True
63+
5064
<# FUNCTIONS #>
5165
. $PSScriptRoot\_Mods-Functions.ps1
5266

5367
<# MAIN #>
54-
if ($Run) {
55-
Invoke-ModsApp $Run $RunSwitch $RunWait
68+
if ($RunSystem) {
69+
Invoke-ModsApp $RunSystem $RunSwitch $RunWait ""
5670
}
5771
if ($Proc) {
5872
Stop-ModsProc $Proc
@@ -78,8 +92,14 @@ if ($DelFile) {
7892
if ($CopyFile -and $CopyTo) {
7993
Copy-ModsFile $CopyFile $CopyTo
8094
}
95+
if ($File -and $FindText -and $ReplaceText) {
96+
Edit-ModsFile $File $FindText $ReplaceText
97+
}
8198
if ($GrantPath) {
8299
Grant-ModsPath $GrantPath
83100
}
101+
if ($RunUser) {
102+
Invoke-ModsApp $RunUser "" "" $User
103+
}
84104

85105
<# EXTRAS #>

mods/_Mods-Functions.ps1

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
#Common shared functions for mods handling
22

3-
function Invoke-ModsApp ($Run, $RunSwitch, $RunWait) {
3+
function Invoke-ModsApp ($Run, $RunSwitch, $RunWait, $User) {
44
if (Test-Path "$Run") {
5-
if (!$RunWait) {
6-
Start-Process $Run -ArgumentList $RunSwitch
7-
}
8-
else {
9-
Start-Process $Run -ArgumentList $RunSwitch -Wait
10-
}
5+
if (!$RunSwitch) {$RunSwitch = " "}
6+
if (!$User) {
7+
if (!$RunWait) {
8+
Start-Process $Run -ArgumentList $RunSwitch
9+
}
10+
else {
11+
Start-Process $Run -ArgumentList $RunSwitch -Wait
12+
}
13+
}
14+
else {
15+
Start-Process explorer $Run
16+
}
1117
}
1218
Return
1319
}
@@ -192,6 +198,13 @@ function Copy-ModsFile ($CopyFile, $CopyTo) {
192198
Return
193199
}
194200

201+
function Edit-ModsFile ($File, $FindText, $ReplaceText) {
202+
if (Test-Path "$File") {
203+
((Get-Content -path $File -Raw) -replace "$FindText","$ReplaceText") | Set-Content -Path $File -Force -ErrorAction SilentlyContinue | Out-Null
204+
}
205+
Return
206+
}
207+
195208
function Grant-ModsPath ($GrantPath) {
196209
foreach ($path in $GrantPath)
197210
{

0 commit comments

Comments
 (0)