|
I can't do impersonation here at work. I have to wait until I get home to examine the code.
|
|
|
|
|
gobbo-dd wrote: I compared two processes with process explorer and the only thing that I realized was that "normal" processes have security attribute "NT AUTHORITY\INTERACTIVE" which the process I am starting has not ... There's a nice hint.
If you ever created a Windows Service, you'll remember that you cannot access the desktop or interact with it if that flag is not set.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yeah, I know. But according to the documentation here CreateProcessWithTokenW it says:
Quote: If the lpDesktop member is NULL or an empty string, the new process inherits the desktop and window station of its parent process. The function adds permission for the specified user account to the inherited window station and desktop. Otherwise, if this member specifies a desktop, it is the responsibility of the application to add permission for the specified user account to the specified window station and desktop, even for WinSta0\Default.
So how should I set this interactive flag if the function is supposed to take care of it ...
|
|
|
|
|
If it is running as another user, it may need to run on its own desktop.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I cant believe. First of all, there is this "runas" functionality which very well creates a GUI on the calling user's desktop. And secondly, the documentation says that it should work ...
Anyone has an idea why it doesn't? Or how I could assign the proper permissions to the process, I create ?
Thanks
Guido
|
|
|
|
|
gobbo-dd wrote: And secondly, the documentation says that it should work ... Where does it say that? On MSDN it states that there are two alternatives if the call fails with an ERROR_PRIVILEGE_NOT_HELD.
gobbo-dd wrote: Anyone has an idea why it doesn't? ..because (AFAIK) you can only interact with windows-objects that belong to your desktop-object; that is user-specific, as it is created after logon. You could create a new desktop-object and show it there.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
it does not fail with "privilege not held" (i had that error 1342 and fixed it ...)
it even shows an icon in the taskbar (as you can see on the screenshot) - which indicates imho that the process is allowed to create "something" on the desktop....
it simply doesn't show the "full window"...
and yes, the documentation says:
Quote: If the lpDesktop member is NULL or an empty string, the new process inherits the desktop and window station of its parent process. The function adds permission for the specified user account to the inherited window station and desktop.
Quote: ..because (AFAIK) you can only interact with windows-objects that belong to your desktop-object; that is user-specific, as it is created after logon. You could create a new desktop-object and show it there.
Again - that is not what the documentation says "... process inherits ... "
Cheers
Guido
|
|
|
|
|
gobbo-dd wrote: which indicates imho that the process is allowed to create "something" on the desktop.... Which is what a service may do also, but it will not be showing a window unless it is marked as 'interactive'.
Found this[^] on SO, where the last answer suggests a possible solution
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
AWESOME
IntPtr hWinSta = GetProcessWindowStation();
WindowStationSecurity ws = new WindowStationSecurity(hWinSta, AccessControlSections.Access);
ws.AddAccessRule(new WindowStationAccessRule("user@domain", WindowStationRights.AllAccess, AccessControlType.Allow));
ws.AcceptChanges();
IntPtr hDesk = GetThreadDesktop(GetCurrentThreadId());
DesktopSecurity ds = new DesktopSecurity(hDesk, AccessControlSections.Access);
ds.AddAccessRule(new DesktopAccessRule("user@domain", DesktopRights.AllAccess, AccessControlType.Allow));
ds.AcceptChanges();
Did the trick. Thank you veeery much for pointing me to this.
Cheers
Guido
|
|
|
|
|
Thank you, for sharing your answer - bookmarked it for future reference
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Congratulations on a solution!
I was just looking at this again last night and didn't get anywhere.
|
|
|
|
|
I have a panel of size width=150 pixel,height=100 pixel, backcolor=green with autoscroll is true. I also have a picturebox within that panel which contains a picture of size width=500 pixel, height=200 pixel. I also have a button, on clicking that button picturebox image rotates 90 degree clockwise. and according to that scrollbar values should change. but it is not.
Here is my code
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim h, w
PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
h = PictureBox1.Image.Height
w = PictureBox1.Image.Width
Panel1.HorizontalScroll.Maximum = 0
Panel1.HorizontalScroll.Visible = False
Panel1.VerticalScroll.Maximum = 0
Panel1.VerticalScroll.Visible = False
Panel1.AutoScroll = False
Panel1.HorizontalScroll.Minimum = 0
Panel1.HorizontalScroll.Maximum = w - 1
Panel1.HorizontalScroll.Visible = True
Panel1.HorizontalScroll.Value = 0
Panel1.VerticalScroll.Minimum = 0
Panel1.VerticalScroll.Maximum = h - 1
Panel1.VerticalScroll.Visible = True
Panel1.VerticalScroll.Value = 0
Panel1.AutoScroll = True
PictureBox1.Left = 0
PictureBox1.Top = 0
Panel1.Invalidate()
End Sub
My problem is: On form load both the scrollbars working perfectly. But after clicking the button picturebox rotates to 90 degrees, so picturebox's images's width and height values interchanges, so the scrollbars maximum values. But its not. After clicking the button first time vscrollbar does not go down after a certain value. This thing happens on odd number of clicking the button. On even number of clicking it works perfectly.
This odd and even number problem also interchanges when the original picturebox image dimension interchanges. i.e. when picturebox image width=200, height=500, then hscrollbar creates the problem on odd number of button clicking.
|
|
|
|
|
The PictureBox is not perfect and if you turn on the borders you should be able to see that it does not resize itself correctly after the image has been rotated. In theory PictureBox.Refresh() or PictureBox.Invalidate() should sort out any problems but in my experience those methods do not help and the picturebox does not seem to know that the image has rotated. What I found helpful was to simply reassign the rotated image to the PictureBox.Image property.
The strange alternate click issue with the Panel's scrollbars tends to happen if you muck about with the scroll properties. I came to the conclusion that Microsoft never meant us to change them!
Alan.
|
|
|
|
|
Hello
Hope it's ok to post this here - it's a general programming query but maybe it should be in "Database"? Anyway...
I've never really understood database connection pooling...
If I want to make a lot of separate database updates I could take one of two approaches:
Do
run some code to prepare SQL command
Open DB connection
Run SQL command
Close DB connection
Loop Or
Open DB connection
Do
run some code to prepare SQL command
Run SQL command
Loop
Close DB connection
Which is the better approach?
Thanks...
|
|
|
|
|
Those aren't separate database-updates. Combine them, execute a single IDbCommand and wrap it in a transaction.
As for the loop; There's a good explanation on MSDN[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Well, I'm not sure to combine a number of statements of the form
insert into table (field1, field2,...) values (?,?,...) on duplicate key update field2 = ?, ... with associated command parameters into one.... (MySQL)
I guess I need to look into using transactions more....
thanks
|
|
|
|
|
A_Griffin wrote: Well, I'm not sure to combine a number of statements of the form In case of doubt, verify.
INSERT statements that use VALUES syntax can insert multiple rows. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas. I don't work with MySQL a lot, but in SQLite there is a very noticeable slowdown if you insert each record separately.
It looks a lot like a bulk-insert. If you don't want to import it in a single go, I'd still recommend doing it at least in batches.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes, for simple inserts MySQL can use bulk inserts as you suggest, but when combined with the "on duplicate key update" option then, as far as I know, this cannot be done.
|
|
|
|
|
|
Yes, thanks - it says nothing there about how (or even if one can) combine multiple such statements into one.
And why, out of interest, would you never use it?
|
|
|
|
|
A_Griffin wrote: Yes, thanks - it says nothing there about how (or even if one can) combine multiple such statements into one. It does, even comes with an example - and a note it might be unsafe.
A_Griffin wrote: And why, out of interest, would you never use it? Because I could not longer guarantee the integrity of the database, which is rather important to me.
What is your key? Let's take a VARCHAR(10) as an example key. There's already an entry "test" in your DB, and the same key occurs in your import-set 15 times. Which of those would you reckon to be the correct one? Which one do you think will be inserted? That may lead to some inconsistencies in a replication-scenario.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The best solution is the one that minimizes the number of "new" connections made (which is extra overhead); and doesn't keep a connection open longer than needed (hogs resources).
In your case, the choice depends on the amount of "looping" and what "run some code" involves; so there is no "one answer".
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Gerry Schmitz wrote: The best solution is the one that minimizes the number of "new" connections made (which is extra overhead); In doubt, open and closing has the preference. Thanks to connection pooling the overhead is limited.
There is a Dokan-implementation in the wild available that emulates a drive using a SQL server database. Opening and closing a connection for each request did not slow the machine down even a tiny bit.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you - that is interesting. I do wonder though, when you say "If in doubt..." - what doubt? Under what circumstances then would one prefer the other option (a single open/close outside the loop)?
|
|
|
|
|