require rb\r
}\r
\r
+Windows::Authorization.runas_admin\r
+\r
home = File.expand_path(ENV["PACKAGE_HOME"])\r
host = Socket.gethostbyname(Socket.gethostname).first\r
options = {\r
OpenDS.install(options) unless options[:ldap_setting]\r
Redmine.install(options)\r
system(%Q["#{ScriptDir}/service.bat" install])\r
-Shortcut.install(options)\r
+Windows::Shortcut.install(options)\r
+++ /dev/null
-require 'win32ole'\r
-require 'win32/shortcut'\r
-\r
-module Shortcut\r
- MENU_DIR = File.join(WIN32OLE.new("WScript.Shell").SpecialFolders("AllUsersPrograms"), "RedmineLE")\r
-\r
- def self.install(options)\r
- service_dir = File.join(MENU_DIR, "service")\r
- Dir.mkdir(MENU_DIR) unless File.directory?(MENU_DIR)\r
- Dir.mkdir(service_dir) unless File.directory?(service_dir)\r
-\r
- Win32::Shortcut.new(File.join(MENU_DIR, "home.url")) {|s|\r
- port = options[:apache_port]\r
- port = port.to_s == "80" ? "" : ":#{port}"\r
- s.path = "http://localhost#{port}/"\r
- }\r
- Win32::Shortcut.new(File.join(MENU_DIR, "uninstall.lnk")) {|s|\r
- s.path = "javaw"\r
- s.arguments = %Q[-jar "#{File.join(options[:home], "Uninstaller/uninstaller.jar")}"]\r
- }\r
-\r
- %w[start stop restart status install uninstall].each {|command|\r
- Win32::Shortcut.new(File.join(service_dir, "#{command}.lnk")) {|s|\r
- s.path = File.join(options[:home], "script/service.bat")\r
- s.arguments = "#{command} & pause"\r
- }\r
- }\r
- end\r
-\r
- def self.uninstall\r
- FileUtils.rm_rf(MENU_DIR)\r
- end\r
-end\r
--- /dev/null
+require 'windows/authorization'
+require 'windows/shortcut'
--- /dev/null
+require 'Win32API'
+require 'win32ole'
+
+module Windows
+ module Authorization
+ def self.admin?
+ Win32API.new("shell32", "IsUserAnAdmin", nil, "i").call != 0
+ end
+
+ def self.runas_admin
+ return if admin?
+
+ buf = [148,0,0,0,0,"\0"*128].pack("LLLLLa128")
+ Win32API.new("kernel32", "GetVersionEx", "p", "i").call(buf)
+ (major, minor) = buf[4,12].unpack("LL")
+
+ # after vista
+ if major >= 6
+ args = [$0, ARGV.join(" "), Dir.pwd, "runas"]
+ WIN32OLE.new("Shell.Application").ShellExecute(*args)
+ exit
+ else
+ raise "it requires administrator authorization."
+ end
+ end
+ end
+end
--- /dev/null
+require 'win32ole'\r
+require 'win32/shortcut'\r
+\r
+module Windows\r
+ module Shortcut\r
+ MENU_DIR = File.join(WIN32OLE.new("WScript.Shell").SpecialFolders("AllUsersPrograms"), "RedmineLE")\r
+\r
+ def self.install(options)\r
+ service_dir = File.join(MENU_DIR, "service")\r
+ Dir.mkdir(MENU_DIR) unless File.directory?(MENU_DIR)\r
+ Dir.mkdir(service_dir) unless File.directory?(service_dir)\r
+\r
+ Win32::Shortcut.new(File.join(MENU_DIR, "home.url")) {|s|\r
+ port = options[:apache_port]\r
+ port = port.to_s == "80" ? "" : ":#{port}"\r
+ s.path = "http://localhost#{port}/"\r
+ }\r
+ Win32::Shortcut.new(File.join(MENU_DIR, "uninstall.lnk")) {|s|\r
+ s.path = "javaw"\r
+ s.arguments = %Q[-jar "#{File.join(options[:home], "Uninstaller/uninstaller.jar")}"]\r
+ }\r
+\r
+ %w[start stop restart status install uninstall].each {|command|\r
+ Win32::Shortcut.new(File.join(service_dir, "#{command}.lnk")) {|s|\r
+ s.path = File.join(options[:home], "script/service.bat")\r
+ s.arguments = "#{command} pause"\r
+ }\r
+ }\r
+ end\r
+\r
+ def self.uninstall\r
+ FileUtils.rm_rf(MENU_DIR)\r
+ end\r
+ end\r
+end\r
#!ruby\r
require 'yaml'\r
require 'win32/service'\r
+require 'windows/authorization'\r
\r
PACKAGE_HOME = File.expand_path(ENV["PACKAGE_HOME"])\r
\r
end\r
end\r
\r
-Service.usage unless command = ARGV.shift\r
+(command, pause) = ARGV[0..1]\r
+Service.usage unless command\r
+if %w[install uninstall start stop restart].include?(command)\r
+ Windows::Authorization.runas_admin\r
+end\r
Service.send(command)\r
\r
+if pause\r
+ print "Press any key to exit..."\r
+ STDIN.gets\r
+end\r
+\r
__END__\r
:end\r
set APR_ICONV_PATH=%PACKAGE_HOME%apache\bin\iconv\r
\r
set RUBYOPT=rubygems\r
+set RUBYLIB=%PACKAGE_HOME%script\lib\r
#!/usr/bin/env ruby\r
\r
+require 'windows'\r
+\r
ScriptDir = File.dirname(__FILE__)\r
-require ScriptDir + "/lib/shortcut.rb"\r
+Windows::Authorization.runas_admin\r
\r
system(%Q["#{ScriptDir}/service.bat" uninstall])\r
-Shortcut.uninstall\r
+Windows::Shortcut.uninstall\r