2013年11月20日 星期三

使用 MSIEXEC.EXE 安裝 msi 時,指定 All Users

MSIEXEC.EXE /I MyPackage.msi
When no value is specified the application is installed "Per User" placing shortcuts in the current user profile.

MSIEXEC.EXE /I MyPackage.msi ALLUSERS=1
This installs shortcuts to the "All Users" profile, only administrators will be able to install the shortcuts in this way.

MSIEXEC.EXE /I MyPackage.msi ALLUSERS=2
For users, this will install the shortcut in the current user profile, for administrators, this will still install the profile for "All Users". As an administrator, if you wish to install the shortcuts in your own local profile, do not specify a value for the ALLUSERS property.

Nicholas Jones, MCITP® | Core Infrastructure Consultant | Sparkhound | https://www.mcpvirtualbusinesscard.com/VBCServer/nicholas.jones/profile

參考網址: http://social.technet.microsoft.com/Forums/systemcenter/en-US/6c0e5bd6-94f1-4d77-b361-e17ecba9783d/sccm-msi-and-allusers-property

2013年10月28日 星期一

RegistryKey.SetValue 遇到 UnauthorizedAccessException


參考網址: http://stackoverflow.com/questions/11768172/c-sharp-registry-setvalue-throws-unauthorizedaccessexception
string user = Environment.UserDomainName + "\\" + Environment.UserName
        RegistryAccessRule rule = new RegistryAccessRule(user,
        RegistryRights.FullControl,
        AccessControlType.Allow);        
RegistrySecurity security = new RegistrySecurity();
security.AddAccessRule(rule);
var key = Microsoft.Win32.Registry.Users.OpenSubKey(Path, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.FullControl);
key.SetAccessControl(security);

2013年9月27日 星期五

javax.xml.ws.WebServiceException: 無法建立 JAXBContext

使用 web service 時如果有 throw exception 的話,會遇到 "javax.xml.ws.WebServiceException: 無法建立 JAXBContext" 的錯誤

java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions java.lang.StackTraceElement does not have a no-arg default constructor.

把 throw exception 拿掉,改用 try..catch 就可以了

2013年9月26日 星期四

javascript 執行減法運算


在 javascript 執行 float 相減時,可能會發生 9.700000000000001 的情形
為防止這個情形發生,必需加上 .toFixed()

例如:
var i = 9.8;
i = (i - 0.1).toFixed(1); // i => 9.7

2013年9月18日 星期三

備份系統安全性記錄檔


參考來源: http://jojochen.blog.ithome.com.tw/post/2529/77642
參考來源: http://msdn.microsoft.com/en-us/library/aa394593%28v=VS.85%29.aspx

以下為 vbs 內容:

=============================

'定義變數BackupName備份事件檢視器檔案
Dim BackupName
Set Fso = CreateObject("Scripting.FileSystemObject")

'定義當日年,月,日
dtmThisDay = Day(Date)
dtmThisMonth = Month(Date)
dtmThisYear = Year(Date)
strBackupName = dtmThisYear & "_" & dtmThisMonth & "_" & dtmThisDay

'設定 WMI 取得 NameSpace 為 root\cimv2 的 Backup 方式
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Backup,Security)}!\\.\root\cimv2")

'WQL 取得 Win32_NTEventLogFile 為安全性記錄檔 security
Set colLogFiles = objWMIService.ExecQuery("Select * from Win32_NTEventLogFile Where LogFileName='security'")
For Each objLogfile in colLogFiles
BackupName = "c:\" & strBackupName &  "_security.evt"
if (Fso.FileExists(BackupName)) then
objLogFile.BackupEventLog("c:\" & strBackupName &  "_security2.evt")
objLogFile.ClearEventLog()
WScript.Echo "File saved: " & strBackupName &  "_security2.evt"
else
objLogFile.BackupEventLog("c:\" & strBackupName &  "_security.evt")
objLogFile.ClearEventLog()
WScript.Echo "File saved: " & strBackupName &  "_security.evt"
end if
Next

Set colLogFiles = Nothing
Set objWMIService = Nothing
Set Fso = Nothing

=============================

更新:
在 windows 2000 執行時遇到 SWbemObject: Access denied 存取遭到拒絕
將 impersonationLevel=impersonate,(Backup) 改成 impersonationLevel=impersonate,(Backup,Security)


2013年9月14日 星期六

解決 sencha touch 2.2.x 在 Chrome 29.x 執行時,textfield 無法顯示的問題


參考來源:http://druckit.wordpress.com/2013/08/22/sencha-touch-2-x-and-google-chrome-29/
There’s a bug in Google Chrome 29 that prevents Sencha Touch 2.2.x apps from displaying properly. While this shouldn’t affect mobile browsers (yet), it will affect you if you use Chrome to debug your apps.
You can patch your Sencha Touch 2.2.x apps by modifying the /touch2/resources/themes/stylesheets/sencha-touch/base/mixins/_Class.scss file, replacing the st-box mixin with the following code:
1
2
3
4
5
6
7
8
9
10
11
@mixin st-box($important: no) {
    @if $important == important {
        display: flex !important;
        display: -webkit-box !important;
        display: -ms-flexbox !important;
    } @else {
        display: flex;
        display: -webkit-box;
        display: -ms-flexbox;
    }
}

2013年8月30日 星期五

response.setHeader 下載檔名遇到中文字的解決方法


response.setContentType("application/x-x509-ca-cert");
response.setContentLength(byteCert.length);
// caname 是中文字
// Safari & Firefox & Chrome
String fileName = new String(caname.getBytes(), "ISO8859-1");

String agent = request.getHeader("USER-AGENT");
if (null != agent && -1 != agent.indexOf("MSIE")) {
    // IE
    fileName = URLEncoder.encode(fileName, "UTF8").replaceAll("\\+", "%20");
}

response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + ".cer\"");

2013年8月23日 星期五

解決 Linux 主機使用 KeyStore 儲存 pfx 時非常慢的問題


在啟動的 shell script 中 (catalina.sh) 加上下列指令

export JAVA_OPTS="$JAVA_OPTS -Djava.security.egd=file:/dev/./urandom"

2013年8月22日 星期四

從 web service 取得 ServletContext 物件

// ServletContextListener Class


public void contextInitialized(ServletContextEvent sce) {
  try {
    sce.getServletContext().setAttribute("myBook", "Learning java");
  } catch (Exception ex) {
  }
}


// WebService


@Resource
WebServiceContext wsContext;

@WebMethod(operationName = "test1")
public String test1() {
  ServletContext servletContext = (ServletContext) wsContext.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
  String myBook = (String) servletContext.getAttribute("myBook");
}

2013年8月14日 星期三

Get viewport size (Nice)


var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0],
x = w.innerWidth || e.clientWidth || g.clientWidth,
y = w.innerHeight|| e.clientHeight|| g.clientHeight;
alert(x);
alert(y);


Reference url: http://stackoverflow.com/questions/3437786/how-to-get-web-page-size-browser-window-size-screen-size-in-a-cross-browser-wa

2013年7月31日 星期三

Post data to a new window with full screen

Javascript Example:


function postDataToNewWindow() {
var myform = document.createElement("form");
myform.setAttribute("method", "post");
myform.setAttribute("action", "verifyCredential.asp");
myform.setAttribute("target", "_custom");

var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "credential");
hiddenField.setAttribute("id", "credential");
hiddenField.setAttribute("value", "2.0");

myform.appendChild(hiddenField);
document.body.appendChild(myform);
window.open("", "_custom", "fullscreen=yes");
myform.submit();
}