10 Replies - 1061 Views - Last Post: 28 March 2013 - 12:53 PM Rate Topic: -----

#1 Graywalker  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 22-February 13

Close Remote Computer Connections

Posted 22 February 2013 - 11:42 AM

I've noticed that when I use File.Exists or RegistryKey.OpenRemoteBaseKey that the remote computer shows me logged in remotely even after the script or program is finished.

How do I close that connection?
Is This A Good Question/Topic? 0
  • +

Replies To: Close Remote Computer Connections

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5582
  • View blog
  • Posts: 11,941
  • Joined: 02-June 10

Re: Close Remote Computer Connections

Posted 22 February 2013 - 12:32 PM

It will drop after x minutes of idle time, or when your application closes.
Was This Post Helpful? 0
  • +
  • -

#3 Graywalker  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 22-February 13

Re: Close Remote Computer Connections

Posted 22 February 2013 - 01:43 PM

Yeah, but my program doesn't close. It stays open - or should - all the time. Its a scanner.
I want to pro-actively close the 'shared resources' connection and/or log off.
Was This Post Helpful? 0
  • +
  • -

#4 Graywalker  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 22-February 13

Re: Close Remote Computer Connections

Posted 05 March 2013 - 02:31 PM

Maybe if I explain a bit more...

I work in an enterprise environment. The program I am working on gathers information that we need to check so we can be sure things on our endpoints are working the way we want them to.

It checks registry entries, file presence and timestamps, OS install date, etc. puts the info into a database and when its gone through all the thousands of computers, it starts over.

Our Information Security department found that the shared resource is left open and they think it is a vulnerability. So, I need to know how to close that shared resource.

I am not sure that IDispose will close the connection on the remote computer and I want to make sure that the shared resource is logged off and closed.

Anyone?
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5582
  • View blog
  • Posts: 11,941
  • Joined: 02-June 10

Re: Close Remote Computer Connections

Posted 05 March 2013 - 03:15 PM

View PostGraywalker, on 05 March 2013 - 03:31 PM, said:

its gone through all the thousands of computers, it starts over.


Its kind of a suspicious circumstance to me - perhaps not to others. Any enterprise with thousands of computers isn't going to be letting a rookie coder make such a program. They would either have an in-house development department of experienced engineers that wouldn't need to ask this, or would be buying any of the numerous commercial software's out there that do this sort of asset inventory.

Besides, if you are just going to loop around and recheck this in a few seconds anyway, it makes little difference. The overhead of keeping the connection open, versus open it/close it/re-open it in 5 seconds is probably a wash anyway.

I also hate to think what this is going to do to your network. Constantly polling all these computers whether or not there is a change is going to impact performance.
Was This Post Helpful? 0
  • +
  • -

#6 Graywalker  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 22-February 13

Re: Close Remote Computer Connections

Posted 06 March 2013 - 06:36 AM

View PosttlhIn`toq, on 05 March 2013 - 03:15 PM, said:

Its kind of a suspicious circumstance to me - perhaps not to others. Any enterprise with thousands of computers isn't going to be letting a rookie coder make such a program. They would either have an in-house development department of experienced engineers that wouldn't need to ask this, or would be buying any of the numerous commercial software's out there that do this sort of asset inventory.

Besides, if you are just going to loop around and recheck this in a few seconds anyway, it makes little difference. The overhead of keeping the connection open, versus open it/close it/re-open it in 5 seconds is probably a wash anyway.

I also hate to think what this is going to do to your network. Constantly polling all these computers whether or not there is a change is going to impact performance.


You are apparently not very aware of enterprise IT departments. We have an asset inventory program. I am one of the people managing it. The only thing my program does is go and check to make sure the agents and antivirus are healthy and doing what they are supposed to do. If not, it tries to repair them. Then it creates a report so I can go through and find very troubled systems to fix or send to another department to have reimaged. Coding is not my job, but it makes my job a lot easier.

There is no commercial software to do what I am doing, which is why I have to do it. Well, we didn't buy the software that would do self-healing no matter what went wrong, which I doubt exists.

A few seconds? HA! Try a day or so.

And Rookie? Yeah, I wrote a program to query AD, write to a slqce database, pull info about the computers from AD, query the computers for information about services and specific files, put that all in the database and then start over after a short wait.

The only thing I haven't been able to figure out and prove is something that apparently nobody else on here, including you, can figure out. And I did it with zero classroom training on the language I chose to do it in.

So, if you want to show me up, then do it by putting up something useful instead of trying to insult me.
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5582
  • View blog
  • Posts: 11,941
  • Joined: 02-June 10

Re: Close Remote Computer Connections

Posted 06 March 2013 - 09:08 AM

My apologies. Best of luck with your project. I'll be away from the site for the next several weeks due to my own work commitment.
Was This Post Helpful? 1
  • +
  • -

#8 Graywalker  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 22-February 13

Re: Close Remote Computer Connections

Posted 28 March 2013 - 10:49 AM

Well, its not very elegant, but I've found a solution :

Use wmi to start a process on the remote computer "c:\Windows\System32\net.exe session /delete /y"

It closes all sessions and closes all files opened by remote computers, including the server running the program.

Its a sledgehammer, but apparently Visual Basic .Net does not have a scalpel for this.
Was This Post Helpful? 0
  • +
  • -

#9 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 57
  • View blog
  • Posts: 292
  • Joined: 22-August 11

Re: Close Remote Computer Connections

Posted 28 March 2013 - 11:00 AM

View PostGraywalker, on 22 February 2013 - 01:42 PM, said:

I've noticed that when I use File.Exists or RegistryKey.OpenRemoteBaseKey that the remote computer shows me logged in remotely even after the script or program is finished.

How do I close that connection?


Taken from msdn
Might be helpful. Might not.

Spoiler

This post has been edited by torind_2000: 28 March 2013 - 11:02 AM

Was This Post Helpful? 1
  • +
  • -

#10 Graywalker  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 22-February 13

Re: Close Remote Computer Connections

Posted 28 March 2013 - 11:54 AM

View Posttorind_2000, on 28 March 2013 - 11:00 AM, said:

Taken from msdn
Might be helpful. Might not.

'' This section in particular might be what you're looking for
        ' Close the registry key.
        environmentKey.Close()
''



So, I says to myself, I says "It can't be that simple, can it?" So I look at my code and I do, indeed, already have the .close() on the regread.

... okay, so in one place... but not everywhere it might be needed. So, I put in three more key.close() lines and do my test.

Yep, it closed the connections - for the registry.

Still leaves open a file from a streamreader.
So, I went back and did a .close() on all possible locations of the streamreader.

And, yes, it closed the file for the streamreader. Very Exciting!

... but it still left the session to the remote computer open. Even after the program finished.

:( SO Close!!

No files open, no registry open, but still a session.

(note: using "net session" and "net file" to view open items)

The files closed immediately, but the session was left open for at least 8 minutes, probably longer. When you have an open session on 4000+ computers, it makes Info Security jumpy.

That did improve my code, so thank you very much, torind_2000!!

Still need the "net session /delete /y" though.
Was This Post Helpful? 0
  • +
  • -

#11 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 57
  • View blog
  • Posts: 292
  • Joined: 22-August 11

Re: Close Remote Computer Connections

Posted 28 March 2013 - 12:53 PM

bummer :sad3:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1