How to add a win32 user defined in the sql server to a User defined role wit
h
WMI for sql server
Guess MSSQL_MemberUser would do the trick, but how ? Can someone post a
quick example
Mydomain\User1 as username
My_Role_Read as role name
Win srv 2003 standard
Sql srv 2000 standard with WMI option installed
Thx
MarcFound the solution to my problem thought I'd share
' MyDB is the
target DB
objRoleName = "My_role_MyDB_r" ' Role defined in MyDB
ObjUserName = "NewUser" ' User defined in MyDB
cmdobj = "sp_addrolemember " ' in case I need looping with
variables later on
Set objLocator = CreateObject("wbemscripting.swbemlocator")
' Connect to correct NS
Set ObjServices = ObjLocator.ConnectServer(".", "root\microsoftsqlserver")
' Integrated security version
ObjServices.security_.impersonationlevel = 3
' What DB was that again
set objService2 =
objServices.Get("MSSQL_Database.SQLServerName='(LOCAL)',Name='MyDB'")
' Make the cmd usefull
cmdobj = cmdobj & "'" & objRoleName & "', '" & ObjUserName & "'"
' Let us not wait anylonger do it
objService2.executeimmediate(cmdobj)
Hope this will help someone else
Marc
Showing posts with label trick. Show all posts
Showing posts with label trick. Show all posts
Subscribe to:
Posts (Atom)