I want to make a program that can copy a file to c:\windows\system32\whatever.vbs. The problem is that I get “access denied” when its running.
I have tried to get administrator privileges but the UAC still appears. Can anybody give me a script to run my vbs as administrator and disable UAC when its running?
Here is the code :
option explicit
dim folder, root, f1, source, destination, regedit, WshNetwork
function CopyFile(source, destination)
dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")
If filesys.FileExists(source) Then
filesys.CopyFile source, destination
End If
end function
Set WshNetwork = WScript.CreateObject("WScript.Network")
set folder = CreateObject("Scripting.FileSystemObject")
set root = folder.GetFile(Wscript.ScriptFullName)
source = root
destination = "c:\Documents And Settings\" & WshNetwork.UserName &"\Start Menu\Programs\Startup\whatever.vbs"
call CopyFile(source,destination)
destination = "c:\Windows\System32\whatever.vbs" -> in here access is denied
call CopyFile(Source,destination)
You need to run this script as an Administrator or a user will Administrator privileges:
You can alternatively run it in an elevated Command Prompt or disable UAC entirely:
… and reboot the system.
There is no way to programmatically do what it is you are asking. The entire purpose of UAC to “get in the way” of a such script running and throw up a warning when a process attempts privileged access.