Skip to content

Commit

Permalink
renamed vbscript to match project
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbra committed Nov 28, 2014
1 parent 63d63dc commit a8049a2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -37,7 +37,7 @@ test:

SudoEdit.vmb:
rm -f $(PLUGIN).vmb
vim -N -u NONE -c 'ru! plugin/vimballPlugin.vim' -c ':let g:vimball_home=getcwd()' -c ':call append("0", ["autoload/SudoEdit.vim", "doc/SudoEdit.txt", "plugin/SudoEdit.vim", "autoload/sudo.cmd", "autoload/GetPrivileges.vbs"])' -c '$$d' -c ':%MkVimball ${PLUGIN}' -c':q!'
vim -N -u NONE -c 'ru! plugin/vimballPlugin.vim' -c ':let g:vimball_home=getcwd()' -c ':call append("0", ["autoload/SudoEdit.vim", "doc/SudoEdit.txt", "plugin/SudoEdit.vim", "autoload/sudo.cmd", "autoload/SudoEdit.vbs"])' -c '$$d' -c ':%MkVimball ${PLUGIN}' -c':q!'
vim -N -u NONE -c 'ru! vimballPlugin.vim' -c ':so %' -c':q!' ${PLUGIN}.vmb

SudoEdit:
Expand Down
45 changes: 45 additions & 0 deletions autoload/SudoEdit.vbs
@@ -0,0 +1,45 @@
' Small vbs Script to generate an UAC dialog and request copying some privileged file
' Uses UAC to elevate rights, idea taken from:
' http://stackoverflow.com/questions/7044985
'
' Distributed together with the SudoEdit Vim plugin. The Vim License applies
Dim FSO, WshShell, UAC, cmd

' Safety check
' Vim might give more arguments, they will be just ignored
if WScript.Arguments.Count < 3 then
WScript.Echo "Syntax: cscript.exe SudoEdit.vbs [write|read] sourcefile targetfile"
Wscript.Quit 1
end if

Set WshShell = CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set UAC = CreateObject("Shell.Application")
cmd = WshShell.ExpandEnvironmentStrings("%COMSPEC%")

' All given Files exist
If (Not(FSO.FileExists(WScript.Arguments(1)))) Then
WScript.Echo "Files " & WScript.Arguments(1) & " does not exist"
WScript.Quit 2
ElseIf (Not(FSO.FileExists(WScript.Arguments(2))) AND WScript.Arguments(0) = "read") Then
WScript.Echo "Files " & WScript.Arguments(2) & " does not exist"
WScript.Quit 2
END if

if (WScript.Arguments(0) = "write") then
' Write Files (delete source file afterwards, so we can easily check, if the copy worked
UAC.ShellExecute cmd, "/c copy /Y " & WScript.Arguments(2) & " " & WScript.Arguments(1) & " && del /Q " & WScript.Arguments(2), "", "runas", 1
else
' Read Files
UAC.ShellExecute cmd, "/c copy /Y " & WScript.Arguments(1) & " " & WScript.Arguments(2), "", "runas", 1
end if

' Sleep a moment, so that the FileExists check works correctly
' This only works for when writing the file,
' assume the read operation worked....
WScript.Sleep 100
If (FSO.FileExists(WScript.Arguments(1)) AND WScript.Arguments(0) = "write") Then
WScript.Echo "Copy Failed"
WScript.Quit 3
end if
Wscript.Quit 0
8 changes: 4 additions & 4 deletions autoload/SudoEdit.vim
Expand Up @@ -245,8 +245,8 @@ fu! <sid>SudoRead(file) "{{{2
" Use Windows Shortnames (should makeing quoting easy)
let file = shellescape(fnamemodify(a:file, ':p:8'))
let cmd = printf('!%s\%s read %s %s %s', s:dir,
\ (s:IsUAC ? 'GetPrivileges.vbs' : 'sudo.cmd'),
\ file, s:writable_file, join(s:AuthTool, ' '))
\ (s:IsUAC ? 'SudoEdit.vbs' : 'sudo.cmd'),
\ file, s:writable_file, (s:IsUAC ? '' : join(s:AuthTool, ' ')))
else
let cmd='cat ' . shellescape(a:file,1) . ' 2>'. shellescape(s:error_file)
if s:AuthTool[0] =~ '^su$'
Expand Down Expand Up @@ -294,8 +294,8 @@ fu! <sid>SudoWrite(file) range "{{{2
exe 'sil keepalt noa '. a:firstline . ',' . a:lastline . 'w! ' . s:writable_file[1:-2]
let file = shellescape(fnamemodify(a:file, ':p:8'))
let cmd= printf('!%s\%s write %s %s %s', s:dir,
\ (s:IsUAC ? 'GetPrivileges.vbs' : 'sudo.cmd'), file, s:writable_file,
\ join(s:AuthTool, ' '))
\ (s:IsUAC ? 'SudoEdit.vbs' : 'sudo.cmd'), file, s:writable_file,
\ (s:IsUAC ? '' : join(s:AuthTool, ' ')))
else
let cmd=printf('%s >/dev/null 2>%s %s', <sid>Path('tee'),
\ shellescape(s:error_file), shellescape(a:file,1))
Expand Down

0 comments on commit a8049a2

Please sign in to comment.