lib/knj/win_tightvnc.rb in knjrbfw-0.0.115 vs lib/knj/win_tightvnc.rb in knjrbfw-0.0.116
- old
+ new
@@ -1,33 +1,33 @@
class Knj::Win::TightVNC
def initialize(args)
@args = ArrayExt.hash_sym(args)
-
+
@args[:port] = 5900 if !@args[:port]
@args[:port_http] = 5800 if !@args[:http_port]
-
+
raise "No path given." if !@args[:path]
-
+
exefile = @args[:path] + "/WinVNC.exe"
- raise "#{exefile} was not found." if !File.exists?(exefile)
-
+ raise "#{exefile} was not found." if !File.exist?(exefile)
+
@wmi = WIN32OLE.connect("winmgmts://")
processes = @wmi.ExecQuery("SELECT * FROM win32_process")
ended = false
for process in processes do
if process.Name == "WinVNC.exe"
process.Terminate
ended = true
end
end
-
+
sleep 1 if ended
-
+
#print Win::Registry.get(:cur_user, 'Software\ORL\WinVNC3', 'Password', :sz).unpack('H*')[0] + "\n"
#print ["160e9d46f26586ca"].pack('H*').unpack('H*')[0] + "\n"
#exit
-
+
Win::Registry.set(:cur_user, 'Software\ORL\WinVNC3', [
["AutoPortSelect", 1, :dword],
["BlankScreen", 0, :dword],
["DontSetHooks", 0, :dword],
["DontUseDriver", 0, :dword],
@@ -59,67 +59,67 @@
Win::Registry.set(:local_machine, 'Software\ORL\WinVNC3', [
["AllowLoopback", 1, :dword],
["LoopbackOnly", 0, :dword]
])
#password is of this moment only 'kaspernj'.
-
+
@wmi = WIN32OLE.connect("winmgmts://")
processes = @wmi.ExecQuery("SELECT * FROM win32_process")
ended = false
for process in processes do
if process.Name == "WinVNC.exe"
process.Terminate
ended = true
end
end
-
+
sleep 1 if ended
-
+
Knj::Thread.new do
IO.popen(exefile) do |process|
#nothing
end
end
-
+
sleep 1
-
+
@processes = @wmi.ExecQuery("SELECT * FROM win32_process")
for process in @processes do
if process.Name == "WinVNC.exe"
@process = process
break
end
end
-
+
raise "Could not start WinVNC.exe." if !@process
-
+
Kernel.at_exit do
self.close
end
end
-
+
def open?
begin
@process.GetOwner
return true
rescue => e
return false
end
end
-
+
def close
return nil if !@process
-
+
begin
@process.Terminate
rescue => e
if e.class.to_s == "WIN32OLERuntimeError" and e.message.index("Terminate") != nil
#do nothing.
else
raise e
end
end
-
+
@process = nil
@args = nil
@wmi = nil
@processes = nil
end
\ No newline at end of file