Created
April 6, 2019 21:47
-
-
Save christian-korneck/9586a353604813127efbfe7c63b45f03 to your computer and use it in GitHub Desktop.
make unprivileged windows 10 symlink ( python ctypes )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mkUnprivedSymlink(source, target, dir=False): | |
# https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createsymboliclinkw | |
import ctypes | |
import ctypes.wintypes | |
# 0x0 (file) or 0x1 (dir) + 0x2 (unprived mode) | |
dwFlags = 2 if dir == False else 3 | |
CreateSymbolicLinkW = ctypes.WinDLL("kernel32").CreateSymbolicLinkW | |
CreateSymbolicLinkW.restype = ctypes.wintypes.DWORD | |
CreateSymbolicLinkW.argtypes = (ctypes.wintypes.LPCWSTR, ctypes.wintypes.LPCWSTR, ctypes.wintypes.DWORD) | |
ret = CreateSymbolicLinkW(source, target, dwFlags) | |
# 0 = bad | |
if ret == 0: | |
raise ctypes.WinError() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment