Comments (3)
Hi @MilesFarber, thanks for the report and recommendation in your project. It's appreciated <3.
The existing code should already run the process automatically as administrator if admin is not detected.
If we look at this line:
PowerShell Start -Verb RunAs '%0' 2> nul
%0
is the script path. Single quotes are used to handle paths with spaces included. -Verb RunAs
prompts for administrator privileges.
Did this not work for you? In that case what was the full absolute path of the script you were executing? You can also remove 2> nul
and re-run the script to see what was causing the error.
We run today a lot of powershell scripts, but need to inline them to be able to properly execute them using cmd
(batchfile). This makes the code harder to read. This can be acceptable for individual scripts but preferable to keep the global code as readable as possible (i.e. batchfile). The reason to use batchfile is that they're simple to execute without being affected by execution policies of the host operating system. This makes the generated scripts more accessible and easier to execute by many.
from privacy.sexy.
When i tried to run it it said "Right-click on the script and select "Run as administrator"." Then "Press any key to continue..." but now i cannot reproduce it anymore akdfjlghspfhmbfh ANGY
from privacy.sexy.
😃 It can be due to some naming in the path.
PowerShell solution is well-written, and much more robust than this "clever" (hacky) way.
It also allows exiting with same exit code as the previous running process, showing proper error messages etc.
But I'm thinking from the users perspective, would people appreciate more robust approach here with the values given, or readable?
Because right know it's pretty simple to read and follow, but it will get ugly with inlined powershell.
For example, following code is inlined powershell for deleting directory contents (look at how ugly it is):
:: Clear directory contents : "%LOCALAPPDATA%\Microsoft\Windows\INetCache\IE"
PowerShell -ExecutionPolicy Unrestricted -Command "$pathGlobPattern = "^""$($directoryGlob = '%LOCALAPPDATA%\Microsoft\Windows\INetCache\IE'; if ($directoryGlob.EndsWith('\*')) { $directoryGlob } elseif ($directoryGlob.EndsWith('\')) { "^""$($directoryGlob)*"^"" } else { "^""$($directoryGlob)\*"^"" } )"^""; $expandedPath = [System.Environment]::ExpandEnvironmentVariables($pathGlobPattern); Write-Host "^""Searching for items matching pattern: `"^""$($expandedPath)`"^""."^""; $deletedCount = 0; $failedCount = 0; $foundAbsolutePaths = @(); Write-Host 'Iterating files and directories recursively.'; try {; $foundAbsolutePaths += @(; Get-ChildItem -Path $expandedPath -Force -Recurse -ErrorAction Stop | Select-Object -ExpandProperty FullName; ); } catch [System.Management.Automation.ItemNotFoundException] {; <# Swallow, do not run `Test-Path` before, it's unreliable for globs requiring extra permissions #>; }; try {; $foundAbsolutePaths += @(; Get-Item -Path $expandedPath -ErrorAction Stop | Select-Object -ExpandProperty FullName; ); } catch [System.Management.Automation.ItemNotFoundException] {; <# Swallow, do not run `Test-Path` before, it's unreliable for globs requiring extra permissions #>; }; $foundAbsolutePaths = $foundAbsolutePaths | Select-Object -Unique | Sort-Object -Property { $_.Length } -Descending; if (!$foundAbsolutePaths) {; Write-Host 'Skipping, no items available.'; exit 0; }; Write-Host "^""Initiating processing of $($foundAbsolutePaths.Count) items from `"^""$expandedPath`"^""."^""; foreach ($path in $foundAbsolutePaths) {; if (-not (Test-Path $path)) { <# Re-check existence as prior deletions might remove subsequent items (e.g., subdirectories). #>; Write-Host "^""Successfully deleted: $($path) (already deleted)."^""; $deletedCount++; continue; }; try {; Remove-Item -Path $path -Force -Recurse -ErrorAction Stop; $deletedCount++; Write-Host "^""Successfully deleted: $($path)"^""; } catch {; $failedCount++; Write-Warning "^""Unable to delete $($path): $_"^""; }; }; Write-Host "^""Successfully deleted $($deletedCount) items."^""; if ($failedCount -gt 0) {; Write-Warning "^""Failed to delete $($failedCount) items."^""; }"
I think we should keep the issue with another name, but I'm not sure if it's good to do this or not due to mentioned concern.
from privacy.sexy.
Related Issues (20)
- Show warnings based on script selection HOT 14
- Disable UAC Warning window with script HOT 1
- [BUG]: WI-FI randomly disconnects/crashes HOT 3
- [BUG]: AppImage version fails to run scripts on Fedora HOT 4
- [BUG]: Copilot keeps turning back on after restarting PC HOT 7
- The Application is lacking SEO
- Some scripts that can be used to customize Firefox for better privacy. HOT 3
- [BUG]: Ran the standard protection and now my Windows does not display notifications to apps like Instagram and Whatsapp HOT 4
- Add search options to include/exclude fields HOT 6
- Disable Telemetry for Microsoft's Accessibility Insights for Windows HOT 1
- Implement distinctive visual cues to warn of scripts that are known to break something. HOT 19
- [BUG]: Snipping Tool still can be executable via its keyboard shortcut HOT 9
- [BUG]: Remove Windows Apps doesn't fully remove Xbox Apps HOT 2
- [Feature] The search string as query parameters in the URL HOT 8
- [BUG]: When trying to copy a screenshot by sketching a fragment of the screen (ctrl+shift+s), copying does not happen automatically, an error occurs when trying to copy manually. HOT 4
- Disable Copilot keyboard shortcut (Windows key + C) HOT 5
- Apple silicon processor support HOT 11
- [BUG]: After applying Standard selection Phone Link is broken HOT 9
- [BUG]: Error Running Script HOT 3
- [BUG]: Something in standard script selection breaks "Forgot my password" on the lock screen
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from privacy.sexy.