-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRS_GetEnv.rb
47 lines (44 loc) · 1.48 KB
/
RS_GetEnv.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#================================================================
# The MIT License
# Copyright (c) 2020 biud436
# ---------------------------------------------------------------
# Free for commercial and non commercial use.
#================================================================
#===============================================================================
# 이름 : 환경 변수 획득
# 날짜 : 2018.05.01
# 사용법 :
# 다음과 같이 호출하십시오.
#
# RS.get_env("USERNAME")
#===============================================================================
$imported = {} if $imported.nil?
$imported["RS_GetEnv"] = true
if not defined? Unicode
module Unicode
MultiByteToWideChar = Win32API.new('Kernel32','MultiByteToWideChar','llpipi','i')
WideCharToMultiByte = Win32API.new('Kernel32','WideCharToMultiByte','llpipipp','i')
UTF_8 = 65001
def unicode!
buf = "\0" * (self.size * 2 + 1)
MultiByteToWideChar.call(UTF_8, 0, self, -1, buf, buf.size)
buf
end
def unicode_s
buf = "\0" * (self.size * 2 + 1)
WideCharToMultiByte.call(UTF_8, 0, self, -1, buf, buf.size, nil, nil)
buf.delete("\0")
end
end
class String
include Unicode
end
end
module RS
GetEnvironmentVariableW = Win32API.new('Kernel32', 'GetEnvironmentVariableW', 'ppl', 'l')
def self.get_env(name)
buf = "\0" * 256
GetEnvironmentVariableW.call(name.unicode!, buf, 256)
buf.unicode_s
end
end