Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default User Account

How can I determine if a user is logged in as an Administrator or as a
standard user without Admin priveleges
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default User Account

i cobbled this together, give it a try. it wil put the group in A1 on sheet1

Sub test()
Dim ws As Worksheet
Dim fs As Object

Dim WholeLine As String
Set fs = CreateObject("Scripting.FileSystemObject")
Set ws = Worksheets("Sheet1")
Shell ("C:\windows\system32\cmd /k net user " & Environ("username") &
" d:\test.txt")

Do
Loop Until fs.fileexists("D:\test.txt")
Open "D:\test.txt" For Input Access Read As #1

Do Until InStr(1, WholeLine, "Local Group Memberships")
Line Input #1, WholeLine
Loop
ws.Range("A1").Value = Trim(Split(WholeLine, "*")(1))
Close #1
fs.deleteFile "D:\test.txt"

End Sub


--


Gary Keramidas
Excel 2003


"ajm1949" wrote in message
...
How can I determine if a user is logged in as an Administrator or as a
standard user without Admin priveleges


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default User Account

one other thing i forgot to mention, it uses the D Drive, if you don't have
one, here's one that will work with the C Drive

Sub test2()
Dim ws As Worksheet
Dim fs As Object

Dim WholeLine As String
Set fs = CreateObject("Scripting.FileSystemObject")
Set ws = Worksheets("Sheet1")
Shell ("C:\windows\system32\cmd /k net user " & Environ("username") &
" C:\test.txt")

Do
Loop Until fs.fileexists("D:\test.txt")
Open "C:\test.txt" For Input Access Read As #1

Do Until InStr(1, WholeLine, "Local Group Memberships")
Line Input #1, WholeLine
Loop
ws.Range("A1").Value = Trim(Split(WholeLine, "*")(1))
Close #1
fs.deleteFile "C:\test.txt"

End Sub


--


Gary Keramidas
Excel 2003


"ajm1949" wrote in message
...
How can I determine if a user is logged in as an Administrator or as a
standard user without Admin priveleges


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default User Account

Private Declare Function IsUserAnAdmin Lib "Shell32" () As Boolean

Sub test()

MsgBox IsUserAnAdmin

End Sub

Revert back if the API is ever likely to be used in W9x as it needs an Alias

This doesn't confirm in the UAC is on/off of course

Regards,
Peter T

"ajm1949" wrote in message
...
How can I determine if a user is logged in as an Administrator or as a
standard user without Admin priveleges



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default User Account

Guess this is a typo
Loop Until fs.fileexists("D:\test.txt")

should read
Loop Until fs.fileexists("C:\test.txt")

If doing this in Vista or W7 probably won't be able to save to the root, try
somehting like

sFile = application.defaultfilepath & "\userinfo.txt"

Regards,
Peter T


"Gary Keramidas" wrote in message
...
one other thing i forgot to mention, it uses the D Drive, if you don't
have one, here's one that will work with the C Drive

Sub test2()
Dim ws As Worksheet
Dim fs As Object

Dim WholeLine As String
Set fs = CreateObject("Scripting.FileSystemObject")
Set ws = Worksheets("Sheet1")
Shell ("C:\windows\system32\cmd /k net user " & Environ("username") &
" C:\test.txt")

Do
Loop Until fs.fileexists("D:\test.txt")
Open "C:\test.txt" For Input Access Read As #1

Do Until InStr(1, WholeLine, "Local Group Memberships")
Line Input #1, WholeLine
Loop
ws.Range("A1").Value = Trim(Split(WholeLine, "*")(1))
Close #1
fs.deleteFile "C:\test.txt"

End Sub


--


Gary Keramidas
Excel 2003


"ajm1949" wrote in message
...
How can I determine if a user is logged in as an Administrator or as a
standard user without Admin priveleges






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default User Account

yep. missed it, thanks.

--


Gary Keramidas
Excel 2003


"Peter T" <peter_t@discussions wrote in message
...
Guess this is a typo
Loop Until fs.fileexists("D:\test.txt")

should read
Loop Until fs.fileexists("C:\test.txt")

If doing this in Vista or W7 probably won't be able to save to the root,
try somehting like

sFile = application.defaultfilepath & "\userinfo.txt"

Regards,
Peter T


"Gary Keramidas" wrote in message
...
one other thing i forgot to mention, it uses the D Drive, if you don't
have one, here's one that will work with the C Drive

Sub test2()
Dim ws As Worksheet
Dim fs As Object

Dim WholeLine As String
Set fs = CreateObject("Scripting.FileSystemObject")
Set ws = Worksheets("Sheet1")
Shell ("C:\windows\system32\cmd /k net user " & Environ("username")
& " C:\test.txt")

Do
Loop Until fs.fileexists("D:\test.txt")
Open "C:\test.txt" For Input Access Read As #1

Do Until InStr(1, WholeLine, "Local Group Memberships")
Line Input #1, WholeLine
Loop
ws.Range("A1").Value = Trim(Split(WholeLine, "*")(1))
Close #1
fs.deleteFile "C:\test.txt"

End Sub


--


Gary Keramidas
Excel 2003


"ajm1949" wrote in message
...
How can I determine if a user is logged in as an Administrator or as a
standard user without Admin priveleges





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel to Lock Windows User Account? [email protected] Excel Programming 1 May 19th 07 04:31 PM
Using macros in a second user account Ken W Excel Discussion (Misc queries) 3 November 13th 06 06:20 PM
i share my copmuter. how can i setup seperate new user account sofia New Users to Excel 2 August 20th 06 05:54 PM
Can a service account be embedded in Workbook so that by default the macros are run with service account credentials and not the user credentials??? Divya Sanam Excel Discussion (Misc queries) 0 July 20th 06 05:15 PM
Getting Windows user (Account) from a VBA routine Jacques Brun Excel Programming 7 June 11th 04 11:35 PM


All times are GMT +1. The time now is 11:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"