diff --git a/README.md b/README.md index 07071cd..2e1fd1f 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,8 @@ **WindowsShortcutFull** -view, modify and create windows shortcut files (.lnk) \ No newline at end of file +view, modify and create windows shortcut files (.lnk) + +**RunningAs** + +Alert box containing current user process running as \ No newline at end of file diff --git a/README.md b/README.md index 07071cd..2e1fd1f 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,8 @@ **WindowsShortcutFull** -view, modify and create windows shortcut files (.lnk) \ No newline at end of file +view, modify and create windows shortcut files (.lnk) + +**RunningAs** + +Alert box containing current user process running as \ No newline at end of file diff --git a/RunningAs-Example.go b/RunningAs-Example.go new file mode 100644 index 0000000..8b4195f --- /dev/null +++ b/RunningAs-Example.go @@ -0,0 +1,41 @@ +/*** + * Just a small demonstration script that makes an alert box containing the user the current process is running as + */ +package main + +import ( + "log" + "os/user" + "syscall" + "unsafe" +) + +// MessageBox of Win32 API. +func MessageBox(hwnd uintptr, caption, title string, flags uint) int { + ret, _, _ := syscall.NewLazyDLL("user32.dll").NewProc("MessageBoxW").Call( + uintptr(hwnd), + uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(caption))), + uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))), + uintptr(flags)) + + return int(ret) +} + +// MessageBoxPlain of Win32 API. +func MessageBoxPlain(title, caption string) int { + const ( + NULL = 0 + MB_OK = 0 + ) + return MessageBox(NULL, caption, title, MB_OK) +} + +func main() { + currentUser, err := user.Current() + if err != nil { + log.Fatalf("Unable to get current user: %s", err) + } + userId := currentUser.Username + + MessageBoxPlain("Running as", userId) +}